/* Component layer for Susun.
   Tailwind handles layout and typography; this file holds the few repeated
   controls (pills, buttons, switches) plus the design tokens as CSS variables,
   so a colour only ever has to change in one place. */

:root {
  --susun-page: #f4eada;
  --susun-surface: #fffcf6;
  --susun-surface-sunk: #efe3d0;
  --susun-wood-dark: #5e4028;
  --susun-wood: #8a6141;
  --susun-wood-light: #a87c54;
  --susun-text: #3a2e24;
  --susun-text-soft: #7c6a58;
  --susun-text-muted: #a89785;
  --susun-text-on-accent: #fff8ef;
  --susun-accent: #c06a38;
  --susun-accent-soft: #f6e1d2;
  --susun-sage: #6e8f62;
  --susun-sage-soft: #e2ebdd;
  --susun-gold: #d5a33c;
  --susun-line: #e4d6c0;
  --susun-ring: #c06a38;
  --susun-radius-card: 18px;
}

* {
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow-x: hidden;
}

:focus-visible {
  outline: 3px solid var(--susun-ring);
  outline-offset: 2px;
  border-radius: 6px;
}

/* --- screens --------------------------------------------------------- */

.screen.is-active {
  display: flex;
}

.screen:not(.is-active) {
  display: none !important;
}

.screen[hidden] {
  display: none !important;
}

/* --- pills & buttons ------------------------------------------------- */

.nav-pill,
.lang-pill,
.btn-accent,
.btn-outline,
.btn-soft,
.btn-icon,
.fab,
.toggle-row,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 999px;
  font-weight: 700;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    transform 0.12s ease,
    box-shadow 0.15s ease;
}

.nav-pill {
  padding: 0.5rem 0.9rem;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--susun-text-soft);
  background: transparent;
}

.nav-pill:hover {
  background: var(--susun-surface-sunk);
}

.nav-pill.is-active {
  background: var(--susun-accent-soft);
  color: var(--susun-accent);
  font-weight: 700;
}

.lang-pill {
  padding: 0.3rem 0.75rem;
  font-size: 12px;
  font-weight: 800;
  color: var(--susun-text-soft);
  background: transparent;
}

.lang-pill.is-active {
  background: var(--susun-surface);
  color: var(--susun-text);
  box-shadow: 0 1px 2px rgb(58 46 36 / 0.12);
}

.btn-accent {
  gap: 0.6rem;
  padding: 0.7rem 1.35rem;
  background: var(--susun-accent);
  color: var(--susun-text-on-accent);
  font-size: 15px;
  box-shadow: 0 6px 14px -8px rgb(192 106 56 / 0.9);
}

.btn-accent:hover:not(:disabled) {
  background: #ad5e30;
}

.btn-outline {
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  background: var(--susun-surface);
  border: 1px solid var(--susun-line);
  color: var(--susun-text-soft);
  font-size: 14px;
  font-weight: 600;
}

.btn-outline:hover {
  border-color: var(--susun-wood-light);
  color: var(--susun-text);
}

.btn-soft {
  padding: 0.5rem 0.9rem;
  background: var(--susun-accent-soft);
  color: var(--susun-accent);
  font-size: 14px;
}

.btn-soft:hover:not(:disabled) {
  background: #f1d5c0;
}

.btn-icon {
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: var(--susun-surface-sunk);
  color: var(--susun-text-soft);
}

.btn-icon:hover {
  color: var(--susun-text);
}

.btn-icon[aria-pressed="true"],
.fab[aria-pressed="true"] {
  background: var(--susun-accent);
  color: var(--susun-text-on-accent);
}

.fab {
  justify-content: center;
  width: 46px;
  height: 46px;
  padding: 0;
  background: var(--susun-surface);
  color: var(--susun-text-soft);
  box-shadow: 0 8px 18px -10px rgb(42 27 15 / 0.7);
}

button:disabled,
.fab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* --- difficulty card + switch ---------------------------------------- */

.toggle-row {
  position: relative;
  flex: 1;
  justify-content: flex-start;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: var(--susun-surface-sunk);
  color: var(--susun-text);
  font-weight: 400;
}

.toggle-row:hover {
  background: #e9dbc4;
}

.switch {
  position: relative;
  flex: none;
  width: 42px;
  height: 24px;
  margin-left: auto;
  border-radius: 999px;
  background: #cdbda5;
  transition: background-color 0.15s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  transition: transform 0.15s ease;
}

.toggle-row[aria-pressed="true"] .switch {
  background: var(--susun-sage);
}

.toggle-row[aria-pressed="true"] .switch::after {
  transform: translateX(18px);
}

.chip {
  padding: 0.4rem 0.85rem;
  background: var(--susun-surface);
  border: 1px solid var(--susun-line);
  color: var(--susun-text-soft);
  font-size: 13px;
  font-weight: 600;
}

.chip.is-active {
  background: var(--susun-text);
  border-color: var(--susun-text);
  color: var(--susun-page);
}

/* Mobile bottom navigation: icon over label, 92px wide like the design. */
.bottom-tab {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 0.25rem 0;
  color: var(--susun-text-muted);
  font-size: 11px;
  font-weight: 500;
}

.bottom-tab.is-active {
  color: var(--susun-accent);
  font-weight: 700;
}

.bottom-tab:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Preset option inside the difficulty modal. */
.preset {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.9rem 0.65rem;
  border-radius: 16px;
  border: 1px solid var(--susun-line);
  background: var(--susun-surface);
  text-align: left;
}

.preset.is-active {
  background: var(--susun-accent-soft);
  border-color: var(--susun-accent);
}

.preset-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  width: 44px;
}

.preset-grid i {
  width: 6px;
  height: 6px;
  border-radius: 1.5px;
  background: var(--susun-line);
}

.preset.is-active .preset-grid i {
  background: var(--susun-accent);
}

/* --- gallery card ---------------------------------------------------- */

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--susun-radius-card);
  background: var(--susun-surface);
  border: 1px solid var(--susun-line);
  text-align: left;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.card:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 18px 30px -22px rgb(58 46 36 / 0.85);
}

.card:disabled {
  opacity: 1; /* a locked card is a designed surface, not a greyed-out button */
  cursor: not-allowed;
}

.card-thumb {
  position: relative;
  aspect-ratio: 5 / 3;
  overflow: hidden;
  background: var(--susun-surface-sunk);
}

.card-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-locked .card-thumb img {
  filter: grayscale(1) blur(6px);
  transform: scale(1.06);
}

.card-locked-badge {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem;
  background: rgb(42 27 15 / 0.45);
  color: var(--susun-text-on-accent);
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
}

/* --- mobile tray drawer ---------------------------------------------- */

.tray-track {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tray-track::-webkit-scrollbar {
  display: none;
}

/* One slot per piece. Fixed size on desktop (94px, as the design), flexible on
   mobile so four of them fill the width. */
.tray-slot {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 78px;
  height: 76px;
  border-radius: 14px;
  background: var(--susun-surface-sunk);
  overflow: hidden;
  touch-action: none;
}

.tray-slot canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.tray-slot.is-picked {
  outline: 3px solid var(--susun-accent);
  outline-offset: -3px;
}

@media (min-width: 1024px) {
  .tray-slot {
    width: 94px;
    height: 94px;
  }
}

.tray-empty {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--susun-text-muted);
}

/* Says how a piece is turned. Only ever shown for a puzzle with rotation on. */
.tray-tip {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--susun-text-muted);
}

/* Segmented control for the tray filter. */
.tray-seg {
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--susun-text-soft);
  background: transparent;
}

.tray-seg.is-active {
  background: var(--susun-surface);
  color: var(--susun-text);
  box-shadow: 0 1px 2px rgb(58 46 36 / 0.12);
}

/* --- misc ------------------------------------------------------------ */

#table-surface {
  /* A little grain, so the flat brown does not look like a plain div. */
  background-image:
    radial-gradient(
      circle at 20% 30%,
      rgb(255 255 255 / 0.05),
      transparent 55%
    ),
    radial-gradient(circle at 80% 70%, rgb(0 0 0 / 0.12), transparent 60%),
    repeating-linear-gradient(
      92deg,
      rgb(0 0 0 / 0.05) 0 2px,
      transparent 2px 7px
    );
}

#stage {
  /* input.js sets touch-action itself; this keeps the first paint correct too. */
  touch-action: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
  .card:hover:not(:disabled) {
    transform: none;
  }
}

/* [hidden] must beat Tailwind utilities that set display. */
[hidden] {
  display: none !important;
}
