/* Design tokens — lacquered wood + felt + bone tile world (see spec §11).
   Kept as CSS custom properties so both hand-written rules here and the
   Tailwind config (index.html <script>) share one source of truth. */
:root {
  --rosewood-950: #2A1712;
  --rosewood-900: #38211A;
  --felt-600: #3E6350;
  --felt-500: #4F7A63;
  --bone-100: #EDE2CC;
  --ink-900: #201811;
  --brass-400: #B8935A;
  --lacquer-700: #7A2530;
  --lapis-600: #35597D;

  --font-display: 'Fraunces', serif;
  --font-body: 'Poppins', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  background: radial-gradient(ellipse at top, var(--rosewood-900), var(--rosewood-950) 70%);
}
button { font-family: inherit; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; }

.font-mono { font-family: var(--font-mono); }

/* ---------- boot / loading ---------- */
.boot-loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.boot-spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--brass-400);
  border-top-color: transparent;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- shared screen shell ---------- */
.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem max(1.25rem, env(safe-area-inset-bottom));
}
.screen-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--bone-100);
}
.screen-subtitle {
  color: color-mix(in srgb, var(--bone-100) 70%, transparent);
  font-size: 0.9rem;
  margin: 0.35rem 0 1.5rem;
}
.sub-header {
  display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.25rem;
}
.btn-back {
  background: var(--rosewood-900);
  border: 1px solid color-mix(in srgb, var(--brass-400) 40%, transparent);
  color: var(--bone-100);
  width: 2.25rem; height: 2.25rem; border-radius: 999px;
  font-size: 1.1rem; line-height: 1; cursor: pointer;
}

/* ---------- brand logo (hand-drawn SVG, no webfont dependency) ---------- */
.brand-logo {
  width: 84px; height: 84px; margin: 0 auto 1rem;
  background-repeat: no-repeat; background-size: contain; background-position: center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 120'%3E%3Crect x='8' y='8' width='104' height='104' rx='18' fill='%23EDE2CC' stroke='%23B8935A' stroke-width='4'/%3E%3Cpath d='M35 75 C40 40, 80 40, 85 75' stroke='%237A2530' stroke-width='7' fill='none' stroke-linecap='round'/%3E%3Ccircle cx='45' cy='55' r='5' fill='%2335597D'/%3E%3Ccircle cx='75' cy='55' r='5' fill='%2335597D'/%3E%3C/svg%3E");
}
.brand-logo-sm { width: 56px; height: 56px; margin-bottom: 0.5rem; }
.brand-wordmark {
  font-family: var(--font-display);
  font-size: 2rem; font-weight: 700; text-align: center;
  color: var(--bone-100);
}

/* ---------- gate screen ---------- */
.gate-screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 2rem 1.5rem;
}
.gate-card {
  max-width: 26rem; text-align: center;
  background: var(--rosewood-900);
  border: 1px solid color-mix(in srgb, var(--brass-400) 35%, transparent);
  border-radius: 1.25rem;
  padding: 2rem 1.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.gate-title { font-size: 1.4rem; margin-bottom: 0.5rem; }
.gate-platform {
  display: inline-block; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--brass-400); margin-bottom: 1.25rem;
}
.gate-steps {
  text-align: left; padding-left: 1.25rem; margin: 0; color: var(--bone-100);
  display: flex; flex-direction: column; gap: 0.6rem; font-size: 0.95rem; line-height: 1.4;
}

/* ---------- forms / buttons ---------- */
.text-input {
  width: 100%; padding: 0.85rem 1rem; border-radius: 0.75rem;
  border: 1px solid color-mix(in srgb, var(--brass-400) 45%, transparent);
  background: var(--rosewood-950); color: var(--bone-100);
  font-size: 1rem; margin-bottom: 0.75rem;
}
.text-input:focus { outline: 2px solid var(--brass-400); outline-offset: 1px; }
.form-error { color: #E4A0A8; font-size: 0.85rem; margin: -0.25rem 0 0.75rem; }
.btn {
  border: none; border-radius: 0.85rem; padding: 0.85rem 1.25rem;
  font-family: var(--font-body); font-weight: 600; font-size: 1rem;
  cursor: pointer; transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--brass-400); color: var(--ink-900); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary {
  background: var(--rosewood-900); color: var(--bone-100);
  border: 1px solid color-mix(in srgb, var(--brass-400) 40%, transparent);
}
.btn-lg { padding: 1.1rem 1.5rem; font-size: 1.1rem; }
.btn-sm { padding: 0.5rem 0.9rem; font-size: 0.85rem; }

/* ---------- onboarding ---------- */
.onboarding-screen, .menu-screen { align-items: center; justify-content: center; }
.onboarding-card { width: 100%; max-width: 22rem; text-align: center; }

/* ---------- main menu ---------- */
.menu-header { text-align: center; margin-bottom: 2.5rem; }
.menu-greeting { color: color-mix(in srgb, var(--bone-100) 65%, transparent); margin-top: 0.35rem; }
.menu-level { color: var(--brass-400); font-family: var(--font-mono); font-size: 0.85rem; margin-top: 0.2rem; }
.menu-nav { display: flex; flex-direction: column; gap: 0.85rem; width: 100%; max-width: 22rem; }

/* ---------- layout picker ---------- */
.layout-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.layout-card {
  background: var(--rosewood-900);
  border: 1px solid color-mix(in srgb, var(--brass-400) 35%, transparent);
  border-radius: 1rem; padding: 1.25rem 0.75rem; text-align: center; cursor: pointer;
  color: var(--bone-100); font-weight: 600;
}
.layout-card:active { transform: scale(0.97); }
.layout-card-icon { font-size: 2rem; display: block; margin-bottom: 0.5rem; }

/* ---------- game HUD / toolbar ---------- */
.game-screen { padding-left: 0.5rem; padding-right: 0.5rem; }
.game-hud {
  display: flex; align-items: center; gap: 1rem; padding: 0.5rem 0.5rem 0.75rem;
}
.hud-stat { display: flex; flex-direction: column; align-items: center; font-size: 0.7rem; }
.hud-label { color: color-mix(in srgb, var(--bone-100) 60%, transparent); text-transform: uppercase; letter-spacing: 0.05em; }
.hud-value { font-size: 1rem; color: var(--brass-400); }
.hud-value.is-critical { color: var(--lacquer-700); animation: time-critical-pulse 1s ease-in-out infinite; }
@keyframes time-critical-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.hud-tiles-left { margin-left: auto; font-size: 1.1rem; color: var(--bone-100); }

.board-viewport {
  flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center;
  -webkit-overflow-scrolling: touch;
}
.board-scatter { position: relative; transform-origin: top center; }

.game-toolbar {
  display: flex; justify-content: center; gap: 1.25rem;
  padding: 0.85rem 0.5rem max(0.85rem, env(safe-area-inset-bottom));
}
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  background: var(--rosewood-900);
  border: 1px solid color-mix(in srgb, var(--brass-400) 35%, transparent);
  border-radius: 1rem; padding: 0.6rem 1.1rem; color: var(--bone-100); cursor: pointer;
}
.tool-btn:disabled { opacity: 0.35; }
.tool-icon { font-size: 1.35rem; }
.tool-count { font-family: var(--font-mono); font-size: 0.75rem; color: var(--brass-400); }

/* ---------- tiles ---------- */
.tile {
  position: absolute;
  width: var(--tile-w); height: var(--tile-h);
  border-radius: 6px;
  background: var(--bone-100);
  border: 1px solid color-mix(in srgb, var(--ink-900) 25%, transparent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-family: var(--font-display); font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease, opacity 0.2s ease;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.35) inset,
    0 calc(2px + var(--layer) * 2px) calc(3px + var(--layer) * 3px) rgba(0,0,0,0.45);
}
.tile-main { font-size: calc(var(--tile-w) * 0.46); line-height: 1; }
.tile-marker { font-size: calc(var(--tile-w) * 0.27); line-height: 1; opacity: 0.75; }
.tile[data-suit="character"] { color: var(--lacquer-700); }
.tile[data-suit="bamboo"] { color: var(--felt-600); }
.tile[data-suit="dot"] { color: var(--lapis-600); }
.tile[data-suit="wind"] { color: var(--ink-900); }
.tile[data-suit="dragon-red"] { color: var(--lacquer-700); }
.tile[data-suit="dragon-green"] { color: var(--felt-600); }
.tile[data-suit="dragon-white"] { color: var(--ink-900); background: var(--bone-100); box-shadow: 0 0 0 2px var(--brass-400) inset, 0 2px 4px rgba(0,0,0,0.4); }
.tile[data-suit="season"], .tile[data-suit="flower"] { color: var(--brass-400); font-style: italic; }

.tile.is-blocked { filter: brightness(0.72) saturate(0.7); cursor: not-allowed; }
.tile.is-selected {
  transform: translateY(-6px) scale(1.04);
  box-shadow: 0 0 0 3px var(--brass-400), 0 10px 16px rgba(0,0,0,0.5);
  z-index: 999 !important;
}
.tile.is-hinted { animation: hint-pulse 0.9s ease-in-out 2; }
@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 3px transparent, 0 2px 4px rgba(0,0,0,0.4); }
  50% { box-shadow: 0 0 0 3px var(--brass-400), 0 2px 4px rgba(0,0,0,0.4); }
}
.tile.is-removed {
  opacity: 0; transform: scale(0.4) rotate(12deg); pointer-events: none;
}

/* Signature "csempemosás" (tile-wash) shuffle animation. This is the one
   deliberately elaborate motion moment in the app - every other transition
   (hover/select/error) stays fast and understated on purpose (spec §11). */
.tile.is-shuffling {
  transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s ease;
}

/* ---------- result screen ---------- */
.result-screen { align-items: center; justify-content: center; text-align: center; }
.result-card { max-width: 22rem; }
.result-score { font-size: 1.75rem; color: var(--brass-400); margin: 0.75rem 0; }
.result-detail { color: color-mix(in srgb, var(--bone-100) 70%, transparent); margin-bottom: 1.5rem; }

/* ---------- leaderboard ---------- */
.layout-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; overflow-x: auto; }
.layout-tab {
  flex: none; padding: 0.5rem 0.9rem; border-radius: 999px; font-size: 0.85rem;
  background: var(--rosewood-900); border: 1px solid transparent; color: var(--bone-100); cursor: pointer;
}
.layout-tab.is-active { border-color: var(--brass-400); color: var(--brass-400); }
.leaderboard-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.leaderboard-list li {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--rosewood-900); border-radius: 0.75rem; padding: 0.65rem 0.9rem;
}
.leaderboard-rank { font-family: var(--font-mono); color: var(--brass-400); width: 1.75rem; }
.leaderboard-name { flex: 1; font-weight: 600; }
.leaderboard-score { font-family: var(--font-mono); color: var(--bone-100); }

/* ---------- redeem ---------- */
.redeem-form { display: flex; flex-direction: column; gap: 0.5rem; max-width: 22rem; }
.redeem-message { padding: 0.75rem 1rem; border-radius: 0.75rem; background: var(--rosewood-900); max-width: 22rem; }
.redeem-message.is-success { color: #9fd6b2; }
.redeem-message.is-error { color: #E4A0A8; }

/* ---------- profile ---------- */
.profile-card { max-width: 22rem; }
.profile-username-form { display: flex; gap: 0.5rem; align-items: flex-start; margin-bottom: 1.5rem; }
.profile-username-form .text-input { margin-bottom: 0; }
.profile-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin: 0; }
.profile-stats div { background: var(--rosewood-900); border-radius: 0.75rem; padding: 0.75rem; }
.profile-stats dt { font-size: 0.7rem; color: color-mix(in srgb, var(--bone-100) 60%, transparent); text-transform: uppercase; }
.profile-stats dd { margin: 0.15rem 0 0; font-family: var(--font-mono); font-size: 1.1rem; color: var(--brass-400); }

/* ---------- responsive ---------- */
@media (max-width: 380px) {
  .layout-grid { grid-template-columns: 1fr; }
  .profile-stats { grid-template-columns: 1fr; }
}
