/* ============================================================
   RESET
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ============================================================
   TOKENS
   ============================================================ */

:root {
  --bg:            #060a0f;
  --surface:       #0d1520;
  --surface-2:     #111c2a;
  --border:        rgba(180, 200, 240, 0.07);
  --border-mid:    rgba(180, 200, 240, 0.14);
  --border-active: rgba(180, 200, 240, 0.28);

  --text:          #cbc6bc;
  --text-muted:    #52606e;
  --text-dim:      #2e3a48;

  --correct:       #326655;
  --correct-text:  #c8e8dc;
  --present:       #7a5c28;
  --present-text:  #eeddb8;
  --absent:        #161e2a;
  --absent-text:   #38485a;

  --accent:        #6aa89c;
  --win:           #4a9e84;
  --loss:          #7a4444;

  --tile-size:     56px;
  --tile-gap:      6px;
  --tile-radius:   5px;

  --font-display:  'Fraunces', Georgia, 'Times New Roman', serif;
  --font-ui:       'DM Sans', system-ui, -apple-system, sans-serif;
  --ease:          cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   BASE
   ============================================================ */

html { height: 100%; }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Very faint radial gradient to give the bg some depth */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(80, 120, 180, 0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ============================================================
   SHELL & COLUMN
   ============================================================ */

.shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.game-column {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: 22px;
  padding: 8px 28px 32px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.5);
}

/* ============================================================
   HEADER / TOPBAR
   ============================================================ */

.topbar {
  width: 100%;
  padding: 28px 0 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}

.brand {
  text-align: center;
}

.brand h1 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 30px;
  letter-spacing: 0.06em;
  color: var(--text);
  line-height: 1;
}

.brand-sep {
  color: var(--accent);
  font-weight: 400;
  margin: 0 2px;
}

.tagline {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 6px;
}

/* meta row */
.meta-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: center;
}

.meta-pill {
  display: flex;
  align-items: baseline;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 4px 13px;
}

.meta-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.meta-pill strong {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.new-btn,
.help-btn,
.sound-toggle {
  background: transparent;
  border: 1px solid var(--border-mid);
  border-radius: 30px;
  padding: 5px 18px;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 180ms, background 180ms, color 180ms;
}

.sound-toggle {
  min-width: 86px;
}

.new-btn:hover,
.new-btn:focus-visible,
.help-btn:hover,
.help-btn:focus-visible,
.sound-toggle:hover,
.sound-toggle:focus-visible {
  border-color: var(--accent);
  background: rgba(106, 168, 156, 0.07);
  color: var(--text);
  outline: none;
}

.sound-toggle.is-off {
  color: var(--text-muted);
}

/* ============================================================
   HINT & STATUS
   ============================================================ */

.hint-text {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.01em;
  padding: 0 12px;
  min-height: 18px;
  margin-bottom: 10px;
  font-style: italic;
}

.status-line {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  min-height: 22px;
  margin-bottom: 20px;
  transition: color 200ms;
  letter-spacing: 0.01em;
}

.status-line.win  { color: var(--win);  font-weight: 500; }
.status-line.loss { color: var(--loss); }

/* ============================================================
   BOARD
   ============================================================ */

.board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 26px;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  grid-template-rows: repeat(6, var(--tile-size));
  gap: var(--tile-gap);
  outline: none;
}

/* ============================================================
   TILES
   ============================================================ */

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  border-radius: var(--tile-radius);
  color: var(--text);
  background: transparent;
  text-transform: uppercase;
  user-select: none;
  transition: border-color 80ms;
  /* perspective for the flip */
  perspective: 400px;
}

.tile.filled {
  border-color: var(--border-active);
  animation: tile-pop 90ms var(--ease);
}

/* State classes applied after scoring */
.tile.correct { --rc: var(--correct); --rt: var(--correct-text); }
.tile.present { --rc: var(--present); --rt: var(--present-text); }
.tile.absent  { --rc: var(--absent);  --rt: var(--absent-text);  }

.tile.correct,
.tile.present,
.tile.absent {
  animation: tile-reveal 500ms var(--ease) both;
}

.tile.shake {
  animation: tile-shake 380ms ease;
}

/* ============================================================
   TILE ANIMATIONS
   ============================================================ */

@keyframes tile-pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Flip-style reveal: squish to 0 on Y, swap color, expand back */
@keyframes tile-reveal {
  0%  {
    transform: scaleY(1);
    background: transparent;
    border-color: var(--border-active);
    color: var(--text);
  }
  46% {
    transform: scaleY(0);
    background: transparent;
    border-color: var(--border-active);
    color: var(--text);
  }
  54% {
    transform: scaleY(0);
    background: var(--rc);
    border-color: transparent;
    color: var(--rt);
  }
  100% {
    transform: scaleY(1);
    background: var(--rc);
    border-color: transparent;
    color: var(--rt);
  }
}

@keyframes tile-shake {
  0%, 100% { transform: translateX(0); }
  16%  { transform: translateX(-8px); }
  33%  { transform: translateX(8px); }
  50%  { transform: translateX(-6px); }
  67%  { transform: translateX(6px); }
  84%  { transform: translateX(-3px); }
}

/* ============================================================
   KEYBOARD
   ============================================================ */

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  width: 100%;
}

.key-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.key {
  height: 52px;
  min-width: 34px;
  padding: 0 5px;
  border: none;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  letter-spacing: 0.01em;
  transition: background 140ms, color 140ms, opacity 80ms;
}

.key:hover  { background: #1f2d3f; }
.key:active { opacity: 0.7; transform: scale(0.95); }

.key.command {
  min-width: 52px;
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface);
}

.key.correct {
  background: var(--correct);
  color: var(--correct-text);
}

.key.present {
  background: var(--present);
  color: var(--present-text);
}

.key.absent {
  background: var(--absent);
  color: var(--absent-text);
}

/* ============================================================
   MODAL BASE (shared by level + help modals)
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal.hidden { display: none; }

/* ============================================================
   LEVEL MODAL
   ============================================================ */

.level-modal {
  /* Layout comes from .modal. This class is kept as a JS hook and
     a place for any future level-specific overrides. */
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 20, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-active);
  border-radius: 18px;
  padding: 38px 32px 34px;
  max-width: 370px;
  width: 100%;
  text-align: center;
  animation: modal-rise 260ms var(--ease) both;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6);
}

@keyframes modal-rise {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.modal-eyebrow {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.modal-card h2 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 28px;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 8px;
}

.modal-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.difficulty-tabs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.difficulty-tab {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 15px 20px;
  cursor: pointer;
  transition: border-color 160ms, background 160ms;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.difficulty-tab:hover,
.difficulty-tab:focus-visible {
  border-color: var(--border-active);
  outline: none;
}

.difficulty-tab.active {
  border-color: var(--accent);
  background: rgba(106, 168, 156, 0.07);
}

.tab-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  display: block;
}

.tab-desc {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
}

/* ============================================================
   HELP MODAL
   ============================================================ */

.help-modal .modal-card {
  max-width: 420px;
  text-align: left;
  padding: 36px 32px 28px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
}

.help-modal .modal-eyebrow,
.help-modal .modal-card h2,
.help-modal .modal-sub {
  text-align: center;
}

.help-modal .modal-sub {
  margin-bottom: 8px;
}

.help-section {
  margin-top: 22px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.help-section h3 {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 500;
}

.help-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
}

.help-list li {
  padding-left: 14px;
  position: relative;
}

.help-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.6em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.help-list strong {
  color: var(--text);
  font-weight: 600;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--text);
  padding: 5px 0;
}

.legend-tile {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--tile-radius);
  text-transform: uppercase;
  flex-shrink: 0;
}

.legend-tile.correct { background: var(--correct); color: var(--correct-text); }
.legend-tile.present { background: var(--present); color: var(--present-text); }
.legend-tile.absent  { background: var(--absent);  color: var(--absent-text); }

.help-close-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: color 160ms, background 160ms;
}

.help-close-btn:hover,
.help-close-btn:focus-visible {
  color: var(--text);
  background: rgba(180, 200, 240, 0.06);
  outline: none;
}

.help-confirm-btn {
  margin-top: 28px;
  width: 100%;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 30px;
  padding: 9px 18px;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 180ms, color 180ms;
}

.help-confirm-btn:hover,
.help-confirm-btn:focus-visible {
  background: rgba(106, 168, 156, 0.12);
  color: var(--text);
  outline: none;
}

/* ============================================================
   CONFETTI
   ============================================================ */

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.confetti-piece {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  animation: confetti-burst 1.3s ease-out forwards;
  opacity: 0;
}

@keyframes confetti-burst {
  0%   { transform: translate(0,0) rotate(0deg); opacity: 1; }
  75%  { opacity: 0.9; }
  100% { transform: translate(var(--x), var(--y)) rotate(var(--rotation)); opacity: 0; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 390px) {
  :root {
    --tile-size: 50px;
    --tile-gap:  5px;
  }
  .tile   { font-size: 20px; }
  .key    { height: 46px; min-width: 30px; font-size: 13px; }
  .key.command { min-width: 46px; font-size: 9px; }
}

@media (max-height: 680px) {
  :root { --tile-size: 48px; }
  .topbar { padding: 16px 0 14px; margin-bottom: 14px; }
  .board-wrap { margin-bottom: 18px; }
}
