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

:root {
  --visual-viewport-top: 0px;
  --ui-font: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  --ui-wood: #cfc3aa;
  --ui-wood-light: #f1e6cc;
  --ui-wood-mid: #b8ab91;
  --ui-wood-dark: #817765;
  --ui-edge: #5b574f;
  --ui-shadow: #514c43;
  --ui-ink: #24231f;
  --ui-muted: #6c6558;
  --ui-accent: #4d7182;
  --ui-blue: #9ecce5;
  --ui-gold: #e4b93f;
  --ui-red: #ad4d3e;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  background: #1a1a2e;
  font-family: var(--ui-font);
  color: var(--ui-ink);
}

#game-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

#ui {
  position: fixed;
  top: var(--visual-viewport-top);
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(8px, calc(env(safe-area-inset-top) + 6px)) 16px 16px;
  font-family: var(--ui-font);
}

#top-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  pointer-events: all;
  width: min(100%, 1300px);
}

#level-info {
  order: 1;
  min-width: 220px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--ui-wood-light) 0%, var(--ui-wood) 54%, var(--ui-wood-mid) 100%);
  color: var(--ui-ink);
  padding: 0 22px;
  border: 2px solid var(--ui-edge);
  border-radius: 10px;
  font-size: 21px;
  font-weight: 900;
  letter-spacing: 5px;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.48);
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.42),
    inset 0 -5px 0 rgba(98, 88, 72, 0.26),
    0 5px 0 var(--ui-shadow),
    0 10px 14px rgba(0, 0, 0, 0.16);
}

#letters-used {
  order: 2;
  min-width: 96px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #d7e4e8 0%, #b7c9cf 58%, #9daeb4 100%);
  color: #305062;
  padding: 0 18px;
  border: 2px solid var(--ui-edge);
  border-radius: 10px;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 2px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.36),
    inset 0 -5px 0 rgba(65, 79, 85, 0.22),
    0 5px 0 var(--ui-shadow),
    0 10px 14px rgba(0, 0, 0, 0.14);
}

#restart-btn,
#skip-level-btn,
#hint-btn,
#level-select-btn,
#edit-level-btn,
#settings-btn,
#submit-word,
#continue-level-btn,
#loss-restart-btn,
#settings-close,
#load-custom-btn,
#import-actions button,
.pu-btn,
#replay-prompt button,
#tutorial-skip-btn,
#intro-start {
  min-height: 42px;
  background: linear-gradient(180deg, var(--ui-wood-light) 0%, var(--ui-wood) 55%, var(--ui-wood-mid) 100%);
  color: var(--ui-ink);
  border: 2px solid var(--ui-edge);
  padding: 0 22px;
  border-radius: 9px;
  font-size: 16px;
  cursor: pointer;
  font-family: var(--ui-font);
  font-weight: 900;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.42),
    inset 0 -4px 0 rgba(98, 88, 72, 0.24),
    0 4px 0 var(--ui-shadow),
    0 8px 12px rgba(0, 0, 0, 0.14);
  transition: transform 0.08s ease, filter 0.12s ease, box-shadow 0.08s ease;
}

#top-bar button {
  min-width: 100px;
  height: 48px;
}

#hint-btn {
  order: 3;
}

#restart-btn {
  order: 5;
}

#skip-level-btn {
  order: 6;
}

#level-select-btn {
  order: 7;
}

#edit-level-btn {
  order: 8;
}

#restart-btn:hover,
#skip-level-btn:hover,
#hint-btn:hover,
#level-select-btn:hover,
#edit-level-btn:hover,
#settings-btn:hover,
#submit-word:hover,
#continue-level-btn:hover,
#loss-restart-btn:hover,
#settings-close:hover,
#load-custom-btn:hover,
#import-actions button:hover,
.pu-btn:hover,
#replay-prompt button:hover,
#tutorial-skip-btn:hover,
#intro-start:hover {
  filter: brightness(1.08);
}

#restart-btn:active,
#skip-level-btn:active,
#hint-btn:active,
#level-select-btn:active,
#edit-level-btn:active,
#settings-btn:active,
#submit-word:active,
#continue-level-btn:active,
#loss-restart-btn:active,
#settings-close:active,
#load-custom-btn:active,
#import-actions button:active,
.pu-btn:active,
#replay-prompt button:active,
#tutorial-skip-btn:active,
#intro-start:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.34),
    inset 0 -3px 0 rgba(98, 88, 72, 0.22),
    0 1px 0 var(--ui-shadow),
    0 4px 8px rgba(0, 0, 0, 0.12);
}

#hint-btn.hint-open {
  background: linear-gradient(180deg, #f6df9f 0%, #e5bd52 58%, #c99833 100%);
  color: #332915;
  border-color: #6b5a2f;
}

#settings-btn {
  order: 9;
  min-width: 58px;
  width: 50px;
  padding: 0;
  font-size: 25px;
  line-height: 1;
  pointer-events: all;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#hint {
  color: var(--ui-ink);
  font-size: 15px;
  font-weight: 800;
  margin-top: 14px;
  max-width: min(720px, 92vw);
  pointer-events: none;
  background: linear-gradient(180deg, #eee1c5, #c9bda5);
  border: 2px solid var(--ui-edge);
  border-radius: 9px;
  padding: 10px 16px;
  line-height: 1.35;
  text-align: center;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.36),
    0 4px 0 var(--ui-shadow),
    0 9px 14px rgba(0, 0, 0, 0.14);
}

#hint.hint-collapsed {
  display: none;
}

#selected-info {
  color: #3d362b;
  font-size: 16px;
  font-weight: 900;
  margin-top: 12px;
  min-height: 24px;
  letter-spacing: 0.2px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.48);
}

body:not(.show-selection-readout) #selected-info {
  display: none;
}

#selected-info:not(:empty) {
  background: linear-gradient(180deg, #f1e0af, #d4ad45);
  border: 2px solid #786333;
  border-radius: 8px;
  padding: 6px 14px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.36),
    0 3px 0 #665632,
    0 7px 10px rgba(0, 0, 0, 0.12);
}

#word-input-container {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: all;
  z-index: 20;
  transition: bottom 0.15s ease;
}

#word-input-container.hidden {
  display: none;
}

body.mobile-session #word-input-container {
  bottom: calc(158px + env(safe-area-inset-bottom));
}

/* Submit lives next to the input on mobile (ENTER key removed). Stretches to the
   field's height so the two read as a matched pair. */
body.mobile-session #submit-word {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  min-height: 0;
  padding: 0 18px;
  font-size: 16px;
  white-space: nowrap;
}

body.mobile-session #message {
  bottom: calc(214px + env(safe-area-inset-bottom));
  width: min(92vw, 420px);
  text-align: center;
  font-size: 14px;
  line-height: 1.25;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.72);
}

body.mobile-session {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#word-form {
  margin: 0;
  padding: 0;
  display: contents;
}

#word-input {
  width: 240px;
  padding: 12px 16px;
  font-size: 20px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 3px;
  border: 2px solid var(--ui-edge);
  border-radius: 9px;
  background: linear-gradient(180deg, #fff3d6, #d8c8aa);
  color: var(--ui-ink);
  outline: none;
  font-family: var(--ui-font);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.52),
    inset 0 -3px 0 rgba(90, 82, 70, 0.2),
    0 4px 0 var(--ui-shadow);
}

/* Mobile: compact top bar, keep input visible above keyboard */
@media (max-width: 600px) {
  #top-bar {
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
  }
  #version { flex-basis: 42px; font-size: 8px; letter-spacing: 0.4px; }
  #level-info { min-width: 130px; height: 38px; padding: 0 10px; font-size: 15px; letter-spacing: 2px; }
  #letters-used { min-width: 54px; height: 38px; padding: 0 8px; font-size: 13px; }
  #top-bar button { min-width: 60px; height: 38px; min-height: 38px; }
  #restart-btn, #skip-level-btn, #hint-btn, #level-select-btn, #edit-level-btn { min-width: 60px; height: 38px; min-height: 38px; padding: 0 7px; font-size: 11px; }
  #top-bar #settings-btn { width: 42px; min-width: 42px; height: 38px; min-height: 38px; font-size: 22px; }
  #hint { font-size: 12px; }
  #selected-info { font-size: 14px; margin-top: 4px; }
  #word-input { width: 200px; padding: 10px 12px; font-size: 18px; letter-spacing: 2px; }
  #submit-word { padding: 10px 16px; font-size: 14px; }
  #message { bottom: 80px; font-size: 14px; }
}

/* Narrow/trailer: compact single-row top bar */
@media (max-width: 480px) {
  #ui {
    padding-top: max(4px, calc(env(safe-area-inset-top) + 2px));
    padding-left: 6px;
    padding-right: 6px;
  }
  #top-bar { gap: 3px; }
  #version { display: none; }
  #level-info { min-width: 0; height: 30px; padding: 0 8px; font-size: 12px; letter-spacing: 1px; }
  #letters-used { min-width: 0; height: 30px; padding: 0 6px; font-size: 11px; }
  #top-bar button { min-width: 0; height: 30px; min-height: 30px; padding: 0 7px; font-size: 10px; }
  #top-bar #settings-btn { width: 30px; min-width: 30px; height: 30px; min-height: 30px; font-size: 17px; }
  #hint-btn, #restart-btn, #skip-level-btn, #level-select-btn, #edit-level-btn {
    min-width: 0; height: 30px; min-height: 30px; padding: 0 7px; font-size: 10px;
  }
}

#word-input:focus {
  border-color: #8a6825;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.52),
    inset 0 -3px 0 rgba(90, 82, 70, 0.2),
    0 4px 0 var(--ui-shadow),
    0 0 0 4px rgba(228, 185, 63, 0.24);
}

#submit-word {
  padding: 12px 20px;
  font-size: 16px;
}

#mobile-keyboard {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 9px 8px calc(9px + env(safe-area-inset-bottom));
  border-radius: 14px 14px 0 0;
  background: rgba(8, 13, 20, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom: 0;
  pointer-events: all;
  z-index: 90;
  touch-action: none;
  user-select: none;
  box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.28);
}

#mobile-keyboard.hidden {
  display: none;
}

.mobile-key-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  width: min(100%, 560px);
}

.mobile-key-home {
  width: min(100%, 560px);
}

.mobile-key-bottom {
  width: min(96%, 535px);
}

.mobile-key-spacer {
  display: block;
  flex: 0 0 clamp(14px, 4vw, 28px);
}

.mobile-key-gap {
  flex-basis: clamp(9px, 2.5vw, 18px);
}

.mobile-key-fill {
  flex: 1 1 auto;
}

.mobile-key {
  flex: 0 1 clamp(29px, 8.15vw, 42px);
  min-width: 0;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.09));
  color: rgba(255, 255, 255, 0.92);
  font: 800 14px/1 'Segoe UI', system-ui, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  box-shadow: 0 2px 0 rgba(255, 255, 255, 0.06) inset, 0 2px 6px rgba(0, 0, 0, 0.22);
}

.mobile-key[data-key="TAB"],
.mobile-key[data-key="ENTER"],
.mobile-key[data-key="BACKSPACE"] {
  flex-basis: clamp(54px, 14vw, 76px);
  font-size: 12px;
}

.mobile-key:active {
  background: rgba(255, 215, 0, 0.24);
  color: #fff;
}

.mobile-key[data-key="ENTER"] {
  background: linear-gradient(180deg, rgba(255, 215, 0, 0.88), rgba(218, 173, 0, 0.78));
  color: #1a1a2e;
}

/* Rotate icon fills the TAB key; inverted to read light on the dark key */
.mobile-key-rot {
  height: 34px;
  width: auto;
  filter: invert(1);
  opacity: 0.9;
  pointer-events: none;
  display: block;
}
/* Backspace glyph: large but ~15% smaller, lighter weight so the strokes are thinner */
.mobile-key[data-key="BACKSPACE"] {
  font-size: 26px;
  font-weight: 300;
  line-height: 1;
}

.mobile-key[data-key="TAB"],
.mobile-key[data-key="BACKSPACE"] {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.07));
  color: rgba(255, 255, 255, 0.82);
}

#detonate-btn {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(160px);
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 900;
  background: linear-gradient(180deg, #f1a17f 0%, #d8613e 56%, #a8402b 100%);
  color: #2d160f;
  border: 2px solid #693426;
  border-radius: 9px;
  cursor: pointer;
  pointer-events: all;
  z-index: 30;
  font-family: var(--ui-font);
  letter-spacing: 0.8px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.32);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.32),
    inset 0 -4px 0 rgba(94, 36, 24, 0.24),
    0 4px 0 #5b2b21,
    0 9px 14px rgba(0, 0, 0, 0.18);
  transition: transform 0.08s ease, filter 0.12s ease, box-shadow 0.08s ease;
}

#detonate-btn:hover {
  filter: brightness(1.08);
}

#detonate-btn:active {
  transform: translateX(160px) translateY(3px);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.24),
    0 1px 0 #5b2b21,
    0 5px 9px rgba(0, 0, 0, 0.16);
}

#detonate-btn.hidden {
  display: none;
}

@media (max-width: 600px) {
  #detonate-btn {
    padding: 10px 14px;
    font-size: 13px;
    transform: translateX(120px);
  }
  #detonate-btn:active {
    transform: translateX(120px) translateY(2px);
  }
}

#message {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  color: #b33a2a;
  font-size: 16px;
  font-weight: 900;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.3s;
  max-width: min(92vw, 620px);
  padding: 9px 15px;
  text-align: center;
  line-height: 1.25;
  background: linear-gradient(180deg, #f2e6cc, #cfc3aa);
  border: 2px solid var(--ui-edge);
  border-radius: 9px;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.36),
    0 4px 0 var(--ui-shadow),
    0 9px 12px rgba(0, 0, 0, 0.14);
}

#verb-legend {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: linear-gradient(180deg, #f2e6cc, #cfc3aa);
  color: var(--ui-ink);
  padding: 9px 15px;
  border: 2px solid var(--ui-edge);
  border-radius: 9px;
  font-size: 13px;
  font-weight: 900;
  z-index: 10;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.36),
    0 4px 0 var(--ui-shadow);
}

#verb-legend.hidden {
  display: none;
}

.arrow-icon {
  color: #ff4444;
  font-weight: bold;
}

#level-complete {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(36, 32, 24, 0.62);
  z-index: 100;
  pointer-events: all;
}

#level-complete.hidden {
  display: none;
}

#intermission-panel {
  width: min(560px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  background: linear-gradient(180deg, #f2e6cc, #cfc3aa);
  color: var(--ui-ink);
  border: 2px solid var(--ui-edge);
  border-radius: 12px;
  padding: 34px 38px;
  box-shadow:
    inset 0 5px 0 rgba(255, 255, 255, 0.38),
    inset 0 -6px 0 rgba(98, 88, 72, 0.22),
    0 8px 0 var(--ui-shadow),
    0 18px 26px rgba(0, 0, 0, 0.22);
}

#level-complete h1 {
  color: var(--ui-ink);
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.45);
  margin: 0;
}

#level-complete p {
  color: var(--ui-muted);
  font-size: 18px;
  font-weight: 800;
  margin: 0;
  line-height: 1.45;
}

#social-follow-region {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 18px 0 12px;
}

#social-follow-region.dismissed {
  display: none;
}

.social-follow-label {
  font-size: 13px;
  color: var(--ui-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.social-follow-buttons {
  display: flex;
  gap: 10px;
}

.social-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 800;
  text-decoration: none;
  color: #fff;
  transition: transform 0.12s, filter 0.12s;
}

.social-btn:hover {
  transform: scale(1.07);
  filter: brightness(1.15);
}

.social-x { background: #000; border: 1px solid #333; }
.social-tiktok { background: #111; border: 1px solid #333; }
.social-yt { background: #c00; }


#continue-level-btn {
  min-width: 160px;
  padding: 0 22px;
  font-size: 18px;
}

#continue-level-btn.hidden {
  display: none;
}

#level-outcome-actions {
  display: flex;
  gap: 12px;
  margin-top: 22px;
}

#level-outcome-actions.hidden {
  display: none;
}

#level-outcome-actions button {
  font-size: 18px;
  min-width: 160px;
  min-height: 50px;
  padding: 0 22px;
}

#type-spinner {
  position: fixed;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, #f2e6cc, #cfc3aa);
  padding: 20px 40px;
  border-radius: 10px;
  border: 2px solid var(--ui-edge);
  z-index: 150;
  pointer-events: none;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.36),
    0 5px 0 var(--ui-shadow),
    0 11px 16px rgba(0, 0, 0, 0.16);
}

#type-spinner.hidden {
  display: none;
}

#spinner-word {
  color: var(--ui-muted);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 6px;
  text-transform: uppercase;
}

#spinner-type {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--ui-ink);
  transition: color 0.06s;
}

#spinner-type.verb { color: #2e6d93; }
#spinner-type.noun { color: #7a6c4e; }
#spinner-type.adj  { color: #4a7c59; }

/* ── Settings screen ── */
#settings-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(36, 32, 24, 0.62);
  z-index: 185;
  pointer-events: all;
  padding: max(18px, calc(env(safe-area-inset-top) + 14px)) 18px max(18px, calc(env(safe-area-inset-bottom) + 14px));
}

#settings-screen.hidden {
  display: none;
}

#settings-inner {
  background: linear-gradient(180deg, #f2e6cc, #cfc3aa);
  border: 2px solid var(--ui-edge);
  border-radius: 12px;
  padding: 22px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(880px, 100%);
  max-height: min(760px, calc(100dvh - 36px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: none;
  color: var(--ui-ink);
  box-shadow:
    inset 0 5px 0 rgba(255, 255, 255, 0.38),
    inset 0 -6px 0 rgba(98, 88, 72, 0.22),
    0 8px 0 var(--ui-shadow),
    0 18px 26px rgba(0, 0, 0, 0.22);
}

#settings-inner::-webkit-scrollbar {
  width: 0;
  height: 0;
}

#settings-inner h2 {
  color: var(--ui-ink);
  font-size: 21px;
  letter-spacing: 6px;
  font-weight: 900;
  text-align: center;
  margin: 0;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.44);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  align-items: start;
}

.settings-section {
  padding: 14px 16px 16px;
  background: rgba(255, 248, 226, 0.34);
  border: 2px solid rgba(91, 87, 79, 0.44);
  border-radius: 10px;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.32),
    inset 0 -4px 0 rgba(98, 88, 72, 0.12);
}

.settings-section-lighting {
  grid-column: 2;
  grid-row: 2 / span 2;
}

.settings-section-debug {
  grid-column: 1;
  grid-row: 3;
  background: rgba(217, 207, 185, 0.34);
}

.settings-section h3 {
  color: var(--ui-muted);
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin: 0 0 12px 0;
  font-weight: 900;
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 190px);
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  color: var(--ui-ink);
  font-size: 15px;
  font-weight: 800;
  min-height: 34px;
}

.setting-row:last-child {
  margin-bottom: 0;
}

.setting-row > span:first-child {
  min-width: 0;
}

#settings-screen input[type="range"] {
  width: 100%;
  min-width: 0;
  cursor: pointer;
  accent-color: #8b6a2d;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
}

#settings-screen input[type="range"]::-webkit-slider-runnable-track {
  height: 12px;
  border: 2px solid var(--ui-edge);
  border-radius: 999px;
  background: linear-gradient(180deg, #fff3cf, #c9b88f);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    inset 0 -2px 0 rgba(80, 72, 58, 0.18);
}

#settings-screen input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -8px;
  border: 2px solid #6b5a2f;
  border-radius: 7px;
  background: linear-gradient(180deg, #fff1bf, #d9ad45);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.34),
    0 3px 0 rgba(65, 54, 31, 0.42);
}

#settings-screen input[type="range"]::-moz-range-track {
  height: 12px;
  border: 2px solid var(--ui-edge);
  border-radius: 999px;
  background: linear-gradient(180deg, #fff3cf, #c9b88f);
}

#settings-screen input[type="range"]::-moz-range-progress {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #eac75c, #b98531);
}

#settings-screen input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 2px solid #6b5a2f;
  border-radius: 7px;
  background: linear-gradient(180deg, #fff1bf, #d9ad45);
  box-shadow: 0 3px 0 rgba(65, 54, 31, 0.42);
}

.setting-options {
  display: flex;
  gap: 6px;
}

.setting-options button {
  padding: 6px 14px;
  border-radius: 7px;
  border: 2px solid var(--ui-edge);
  background: linear-gradient(180deg, #e9dcc1, #baae96);
  color: var(--ui-muted);
  font-size: 13px;
  font-family: var(--ui-font);
  font-weight: 900;
  cursor: pointer;
  transition: all 0.12s;
}

.setting-options button:hover {
  filter: brightness(1.07);
  color: var(--ui-ink);
}

.setting-options button.active {
  background: linear-gradient(180deg, #f6df9f, #d6a742);
  border-color: #786333;
  color: #332915;
}

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 84px;
  height: 34px;
  flex-shrink: 0;
  justify-self: end;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #a99d87, #817765);
  border-radius: 9px;
  transition: background 0.15s, border-color 0.15s;
  border: 2px solid var(--ui-edge);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.18),
    inset 0 -3px 0 rgba(36, 35, 31, 0.18),
    0 3px 0 var(--ui-shadow);
}

.toggle-slider::after {
  content: 'OFF';
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(36, 35, 31, 0.78);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.6px;
  z-index: 0;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 32px;
  height: 26px;
  left: 2px;
  top: 2px;
  z-index: 1;
  background: linear-gradient(180deg, var(--ui-wood-light), var(--ui-wood));
  border: 2px solid var(--ui-edge);
  border-radius: 7px;
  transition: transform 0.15s, background 0.15s;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.38),
    0 2px 0 rgba(36, 35, 31, 0.28);
}

.toggle input:checked + .toggle-slider {
  background: linear-gradient(180deg, #f0d687, #d0a243);
  border-color: #6b5a2f;
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(46px);
  background: linear-gradient(180deg, #fff1bf, #e6bd53);
  border-color: #6b5a2f;
}

.toggle input:checked + .toggle-slider::after {
  content: 'ON';
  left: 8px;
  right: auto;
  color: #3b3018;
}

.settings-action {
  justify-self: end;
  min-width: 76px;
  height: 34px;
  padding: 0 14px;
  border: 2px solid var(--ui-edge);
  border-radius: 8px;
  background: linear-gradient(180deg, #efe2c7, #b9ad94);
  color: var(--ui-ink);
  cursor: pointer;
  font-family: var(--ui-font);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.36),
    0 3px 0 var(--ui-shadow);
}

.settings-action:disabled {
  color: rgba(36, 35, 31, 0.34);
  cursor: default;
  filter: grayscale(0.4);
}

.setting-note {
  margin: 8px 0 0;
  color: var(--ui-muted);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 800;
}

#settings-close {
  align-self: center;
  position: sticky;
  bottom: 0;
  z-index: 1;
  padding: 0 36px;
  font-size: 13px;
  letter-spacing: 3px;
  background: linear-gradient(180deg, #f4e8cf, #c4b69b);
}

@media (max-width: 760px) {
  #settings-screen {
    align-items: flex-start;
    padding: max(10px, calc(env(safe-area-inset-top) + 8px)) 10px max(12px, calc(env(safe-area-inset-bottom) + 8px));
  }

  #settings-inner {
    width: 100%;
    max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 18px 14px 16px;
    gap: 12px;
  }

  #settings-inner h2 {
    font-size: 18px;
    letter-spacing: 4px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .settings-section,
  .settings-section-lighting,
  .settings-section-debug {
    grid-column: auto;
    grid-row: auto;
  }

  .setting-row {
    grid-template-columns: minmax(0, 1fr) minmax(112px, 150px);
    gap: 10px;
    font-size: 14px;
  }

  #settings-close {
    position: static;
    width: min(220px, 100%);
  }
}

@media (max-height: 620px) and (min-width: 761px) {
  #settings-inner {
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .settings-grid {
    gap: 10px 12px;
  }

  .settings-section {
    padding: 12px 14px;
  }

  .setting-row {
    margin-bottom: 7px;
    min-height: 30px;
  }
}

#pause-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(36, 32, 24, 0.62);
  z-index: 180;
  pointer-events: all;
}

#pause-screen.hidden {
  display: none;
}

#pause-screen h1 {
  color: #f2e6cc;
  font-size: 48px;
  letter-spacing: 8px;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.34);
}

#pause-screen p {
  color: rgba(242, 230, 204, 0.72);
  font-size: 16px;
  font-weight: 900;
  margin-top: 16px;
}

#level-select {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(119, 157, 160, 0.95) 0%, rgba(42, 56, 58, 0.96) 100%);
  z-index: 190;
  overflow-y: auto;
  padding: 40px 20px;
  box-sizing: border-box;
}

#level-select.hidden {
  display: none;
}

#level-select h2 {
  color: #f2e6cc;
  font-size: 32px;
  letter-spacing: 8px;
  font-weight: 900;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.28);
  margin: 0 0 28px 0;
  flex-shrink: 0;
}

#level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 900px;
  margin-bottom: 24px;
}

.level-btn {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid var(--ui-edge);
  background: linear-gradient(180deg, var(--ui-wood-light), var(--ui-wood) 58%, var(--ui-wood-mid));
  color: var(--ui-ink);
  font-size: 22px;
  font-weight: 900;
  font-family: var(--ui-font);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  padding: 6px;
  transition: transform 0.12s ease, filter 0.12s ease;
  position: relative;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.44);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.38),
    inset 0 -4px 0 rgba(98, 88, 72, 0.22),
    0 4px 0 var(--ui-shadow),
    0 9px 12px rgba(0, 0, 0, 0.14);
  overflow: hidden;
}

.level-btn:hover:not(.locked) {
  filter: brightness(1.08);
  transform: scale(1.05);
}

.level-btn.unlocked {
  border-color: var(--ui-edge);
}

.level-btn.completed {
  border-color: #536f48;
  background: linear-gradient(180deg, #dce8bf, #a7c174);
}

.level-btn.locked {
  opacity: 0.35;
  cursor: not-allowed;
}

.level-btn .lock-icon {
  font-size: 20px;
}

.level-btn .level-num {
  font-size: 22px;
  font-weight: 900;
  z-index: 2;
}

.level-btn .level-score {
  font-size: 9px;
  letter-spacing: 0.5px;
  color: #315165;
  opacity: 0.85;
  z-index: 2;
}

.level-btn .level-label {
  font-size: 10px;
  letter-spacing: 1px;
  opacity: 0.6;
  text-transform: uppercase;
  z-index: 2;
}

/* Real first-frame render fills the whole tile; number/label overlay on top. */
.level-btn .level-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  z-index: 0;
}

.level-btn:has(.level-thumb) .level-num {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 16px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

.level-btn:has(.level-thumb) .level-label,
.level-btn:has(.level-thumb) .level-score {
  position: relative;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  opacity: 0.95;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
}

#level-select-hint {
  color: rgba(242, 230, 204, 0.76);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 2px;
}

#load-custom-btn {
  margin-top: 18px;
  padding: 0 24px;
  font-size: 13px;
  letter-spacing: 1px;
}

.level-btn.custom-level {
  border-color: #405f72;
  background: linear-gradient(180deg, #dbe8ec, #a8c4ce);
  position: relative;
}
.level-btn.custom-level:hover {
  filter: brightness(1.08);
}
.level-btn.custom-level .level-num {
  font-size: 22px;
  color: #315165;
}
.level-btn .clear-custom {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 12px;
  opacity: 0.5;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.level-btn .clear-custom:hover {
  opacity: 1;
  background: rgba(173, 77, 62, 0.26);
}

#import-modal {
  position: fixed;
  inset: 0;
  background: rgba(36, 32, 24, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
#import-modal.hidden { display: none; }
#import-modal-inner {
  background: linear-gradient(180deg, #f2e6cc, #cfc3aa);
  border: 2px solid var(--ui-edge);
  border-radius: 12px;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(520px, 90vw);
  color: var(--ui-ink);
  box-shadow:
    inset 0 5px 0 rgba(255, 255, 255, 0.38),
    inset 0 -6px 0 rgba(98, 88, 72, 0.22),
    0 8px 0 var(--ui-shadow),
    0 18px 26px rgba(0, 0, 0, 0.22);
}
#import-modal-inner h3 {
  color: var(--ui-ink);
  font-size: 18px;
  letter-spacing: 3px;
  margin: 0;
  font-weight: 900;
}
#import-modal-inner p {
  color: var(--ui-muted);
  font-size: 13px;
  font-weight: 800;
  margin: 0;
}
#import-json {
  width: 100%;
  height: 160px;
  background: #fff4dc;
  border: 2px solid var(--ui-edge);
  border-radius: 9px;
  color: var(--ui-ink);
  font-family: monospace;
  font-size: 12px;
  padding: 10px;
  resize: vertical;
  box-sizing: border-box;
}
#import-error {
  color: var(--ui-red);
  font-size: 13px;
  font-weight: 900;
  margin: 0;
}
#import-error.hidden { display: none; }
#import-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
#import-actions button {
  padding: 0 22px;
  font-size: 13px;
  letter-spacing: 1px;
}
#import-ok {
  background: linear-gradient(180deg, #dbe8ec, #a8c4ce) !important;
  border-color: #405f72 !important;
  color: #315165 !important;
}

/* Title screen mirrors the in-game scene: the green/beige checkerboard floor,
   with content on a manilla "instruction card" and DANDLE rendered as the
   game's own cream letter tiles. */
#intro-screen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-conic-gradient(#6aad7a 0% 25%, #ece0c0 0% 50%) 50% 50% / 78px 78px;
  z-index: 200;
  cursor: pointer;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

#intro-screen.hidden {
  display: none;
}

/* Manilla instruction card */
#intro-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: min(92vw, 600px);
  overflow: visible;
  background: linear-gradient(180deg, #f8f1dd 0%, #f1e5c8 100%);
  border: 3px solid #b8a576;
  border-radius: 18px;
  padding: clamp(26px, 5vh, 46px) clamp(22px, 5vw, 52px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.65),
    inset 0 -3px 0 rgba(120, 100, 60, 0.18),
    0 10px 0 #9c8c63,
    0 20px 34px rgba(0, 0, 0, 0.35);
}

#intro-title {
  display: flex;
  justify-content: center;
  gap: clamp(4px, 1.3vw, 10px);
  margin: 0 0 16px 0;
  line-height: 1;
}

/* Each letter is a manilla cube tile, matching the game's letter blocks */
.title-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(38px, 11vw, 74px);
  height: clamp(44px, 12.5vw, 84px);
  background: linear-gradient(180deg, #fbf4e2 0%, #f1e7cf 58%, #e6d9ba 100%);
  color: #2a2620;
  font-family: var(--ui-font);
  font-weight: 900;
  font-size: clamp(26px, 7.5vw, 52px);
  border: 2px solid #9a8a63;
  border-radius: 9px;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.75),
    inset 0 -4px 0 rgba(120, 100, 60, 0.22),
    0 5px 0 #8f7f59,
    0 10px 12px rgba(0, 0, 0, 0.22);
}

.title-tile:nth-child(odd)  { transform: rotate(-2deg); }
.title-tile:nth-child(even) { transform: rotate(2deg); }

#intro-sub {
  font-size: clamp(13px, 2.4vw, 16px);
  font-style: italic;
  color: #7a6f52;
  letter-spacing: 0.5px;
  margin: 0 0 clamp(20px, 5vh, 40px);
  text-align: center;
}

#intro-rules {
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2.2vh, 16px);
  margin-bottom: clamp(22px, 5vh, 44px);
  align-items: flex-start;
  width: 100%;
  padding: clamp(14px, 2.6vh, 20px) clamp(16px, 3.2vw, 26px);
  background: rgba(255, 255, 255, 0.34);
  border: 1px solid rgba(154, 138, 99, 0.4);
  border-radius: 11px;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #3a3322;
  font-size: clamp(13px, 2.7vw, 17px);
  font-weight: 600;
}

.rule-icon {
  width: 26px;
  text-align: center;
  color: #4e8a5f;
  font-size: 15px;
  flex-shrink: 0;
}

.verb-highlight {
  color: #2f6f9a;
}

.verb-highlight strong {
  letter-spacing: 3px;
  color: #2f6f9a;
}

.verb-highlight .rule-icon {
  color: #2f6f9a;
  font-size: 18px;
}

#intro-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(260px, 80%);
}

#intro-loader-bar {
  width: 100%;
  height: 7px;
  background: rgba(120, 100, 60, 0.22);
  border: 1px solid rgba(154, 138, 99, 0.45);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

#intro-loader-bar::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, #5a9d6c, #6aad7a 70%, #8fc89c);
  border-radius: 5px;
  width: var(--progress, 0%);
  transition: width 0.2s ease;
}

#intro-loader-text {
  font-size: 12px;
  letter-spacing: 2px;
  color: #8a7d5c;
}

/* Green "go" button, sharing the 3D block shape of the in-game buttons */
#intro-start {
  font-size: clamp(18px, 3vw, 24px);
  letter-spacing: 6px;
  padding: 0 clamp(36px, 7vw, 56px);
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #84c594 0%, #5fa471 56%, #4f9162 100%) !important;
  color: #f8f1dd !important;
  border-color: #3f6f4c !important;
  text-shadow: 0 1px 0 rgba(40, 70, 50, 0.45) !important;
  animation: introStartGlow 2s ease-in-out infinite;
}

@keyframes introStartGlow {
  0%, 100% { box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.4),
    inset 0 -4px 0 rgba(40, 80, 55, 0.3),
    0 4px 0 #3f6f4c,
    0 8px 12px rgba(0, 0, 0, 0.18); }
  50% { box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.4),
    inset 0 -4px 0 rgba(40, 80, 55, 0.3),
    0 4px 0 #3f6f4c,
    0 8px 12px rgba(0, 0, 0, 0.18),
    0 0 22px rgba(106, 173, 122, 0.7); }
}

#intro-start.hidden {
  display: none;
}

#intro-version {
  margin-top: 22px;
  font-size: 11px;
  letter-spacing: 2px;
  color: rgba(90, 80, 55, 0.5);
  font-family: monospace;
}

@media (max-width: 700px), (max-height: 620px) {
  .rule-item {
    gap: 10px;
  }

  #intro-loader {
    width: min(260px, 72vw);
  }
}

@media (max-width: 600px) {
  body.mobile-session #ui {
    padding: calc(env(safe-area-inset-top) + 6px) 8px 10px;
  }

  body.mobile-session #top-bar {
    max-width: 100%;
  }

  body.mobile-session #word-input-container {
    bottom: calc(158px + env(safe-area-inset-bottom));
    width: min(94vw, 420px);
    justify-content: center;
  }

  body.mobile-session #message {
    bottom: calc(214px + env(safe-area-inset-bottom));
  }

  body.mobile-session #word-input {
    width: min(58vw, 248px);
  }

  body.mobile-session #submit-word {
    align-self: stretch;
    min-height: 0;
    padding: 0 16px;
  }

  body.mobile-session .desktop-control-tip {
    display: none;
  }
}

@media (pointer: coarse), (max-width: 700px) {
  .desktop-control-tip {
    display: none;
  }
}

@media (max-height: 560px) {
  #intro-rules {
    gap: 8px;
    margin-bottom: 18px;
  }

  #intro-sub {
    margin-bottom: 18px;
  }

  #intro-version {
    margin-top: 12px;
  }

  .mobile-key {
    height: 34px;
  }

  #mobile-keyboard {
    gap: 5px;
    padding-top: 7px;
  }

  body.mobile-session #word-input-container {
    bottom: calc(136px + env(safe-area-inset-bottom));
  }

  body.mobile-session #message {
    bottom: calc(188px + env(safe-area-inset-bottom));
  }
}

@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.9; }
}

/* ── Tutorial ── */
#tutorial-overlay {
  position: fixed;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: none;
  transition: opacity 0.4s;
}

#tutorial-overlay.hidden {
  display: none;
}

#tutorial-box {
  background: linear-gradient(180deg, #f2e6cc, #cfc3aa);
  border: 2px solid var(--ui-edge);
  border-radius: 11px;
  padding: 18px 24px 14px;
  text-align: center;
  min-width: 310px;
  max-width: 460px;
  pointer-events: all;
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.38),
    inset 0 -5px 0 rgba(98, 88, 72, 0.2),
    0 6px 0 var(--ui-shadow),
    0 14px 20px rgba(0, 0, 0, 0.18);
}

#tutorial-title {
  color: var(--ui-ink);
  font-size: 19px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 10px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

#tutorial-text {
  color: var(--ui-muted);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.42;
  margin-bottom: 12px;
}

#tutorial-keys {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

#tutorial-keys:empty {
  display: none;
}

.tut-key {
  display: inline-block;
  background: linear-gradient(180deg, #f4d983, #d2a743);
  border: 2px solid #786333;
  border-radius: 7px;
  padding: 3px 10px;
  font-size: 13px;
  color: #332915;
  font-family: monospace;
  font-weight: 900;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.28),
    0 2px 0 #665632;
}

.tut-plus {
  color: var(--ui-muted);
  font-size: 16px;
  font-weight: 900;
  line-height: 28px;
  margin: 0 2px;
}

#tutorial-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
}

#tutorial-step {
  color: var(--ui-muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 2px;
  white-space: nowrap;
}

#tutorial-skip-btn {
  min-height: 30px;
  padding: 0 10px;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.36),
    inset 0 -2px 0 rgba(98, 88, 72, 0.18),
    0 2px 0 var(--ui-shadow);
}

body.mobile-session #tutorial-overlay {
  top: max(126px, calc(env(safe-area-inset-top) + 118px)) !important;
  bottom: auto !important;
  width: min(92vw, 420px);
  z-index: 24;
}

body.mobile-session #tutorial-box {
  min-width: 0;
  max-width: none;
  padding: 12px 16px;
}

body.mobile-session #tutorial-text {
  font-size: 14px;
  line-height: 1.35;
}

@media (pointer: coarse), (max-width: 700px) {
  #tutorial-overlay {
    top: max(126px, calc(env(safe-area-inset-top) + 118px));
    bottom: auto;
    width: min(92vw, 420px);
    z-index: 24;
  }

  #tutorial-box {
    min-width: 0;
    max-width: none;
    padding: 12px 16px;
  }

  #tutorial-text {
    font-size: 14px;
    line-height: 1.35;
  }
}

#version {
  position: static;
  order: 0;
  flex: 0 0 72px;
  color: rgba(36, 35, 31, 0.48);
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
  font-family: monospace;
  font-weight: 900;
  letter-spacing: 1px;
  margin-right: 0;
  text-align: left;
}

#settings-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: all;
}

#settings-links a {
  color: var(--ui-ink);
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
  line-height: 1;
  letter-spacing: 0.5px;
  padding: 2px 0;
}

#settings-links a:hover {
  color: var(--ui-muted);
  text-decoration: underline;
}

#replay-prompt {
  position: fixed;
  top: 86px;
  right: 16px;
  z-index: 900;
  max-width: 280px;
  padding: 14px 16px;
  text-align: left;
  font-family: var(--ui-font);
  background: linear-gradient(180deg, #f2e6cc, #cfc3aa);
  color: var(--ui-ink);
  border: 2px solid var(--ui-edge);
  border-radius: 11px;
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.38),
    inset 0 -5px 0 rgba(98, 88, 72, 0.2),
    0 6px 0 var(--ui-shadow),
    0 14px 20px rgba(0, 0, 0, 0.18);
}

.replay-title {
  color: var(--ui-ink);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  margin-bottom: 6px;
  text-transform: uppercase;
}

#replay-status {
  color: var(--ui-muted);
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 10px;
}

#replay-prompt button {
  min-height: 32px;
  padding: 0 10px;
  margin-right: 5px;
  font-size: 11px;
}

/* Word Challenge */
#word-challenge {
  margin-top: 6px;
  text-align: center;
  pointer-events: none;
}
#word-challenge.hidden { display: none; }
#challenge-label {
  font-size: 13px;
  color: #3d362b;
  font-weight: 900;
  background: linear-gradient(180deg, #f1e0af, #d4ad45);
  border: 2px solid #786333;
  border-radius: 8px;
  padding: 5px 11px;
  display: inline-block;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.42);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.36),
    0 3px 0 #665632;
}
#challenge-bonus {
  font-size: 11px;
  color: var(--ui-muted);
  font-weight: 900;
}

/* Power-up Modal */
#powerup-modal {
  position: fixed;
  inset: 0;
  background: rgba(36, 32, 24, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#powerup-modal.hidden { display: none; }
#powerup-inner {
  background: linear-gradient(180deg, #f2e6cc, #cfc3aa);
  border: 2px solid var(--ui-edge);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  max-width: 500px;
  color: var(--ui-ink);
  box-shadow:
    inset 0 5px 0 rgba(255, 255, 255, 0.38),
    inset 0 -6px 0 rgba(98, 88, 72, 0.22),
    0 8px 0 var(--ui-shadow),
    0 18px 26px rgba(0, 0, 0, 0.22);
}
#powerup-inner h2 {
  color: var(--ui-ink);
  margin-bottom: 8px;
  font-size: 22px;
  letter-spacing: 2px;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.44);
}
#powerup-desc {
  color: var(--ui-muted);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 12px;
}
#powerup-letters {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
#powerup-letters .pu-letter {
  width: 40px; height: 40px;
  background: linear-gradient(180deg, #fff3d6, #d8c8aa);
  color: var(--ui-ink);
  font-weight: 900;
  font-size: 18px;
  border: 2px solid var(--ui-edge);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#powerup-letters .pu-letter:hover {
  filter: brightness(1.07);
}
#powerup-letters .pu-letter.selected {
  border-color: #786333;
  background: linear-gradient(180deg, #f4d983, #d2a743);
  color: #332915;
}
#powerup-types {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.pu-btn {
  padding: 8px 16px;
  font-size: 14px;
  min-width: 100px;
}
.pu-btn small {
  color: var(--ui-muted);
  font-size: 10px;
  font-weight: 800;
}
