:root {
  --cell-size: clamp(34px, min(6vw, calc((100dvh - 350px) / 8)), 62px);
  --cell-gap: clamp(3px, .8vw, 8px);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: var(--gse-font-body);
  background: var(--gse-color-canvas);
}

button, input { font: inherit; }
button { cursor: pointer; }

#game-root, #game-root * {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.board, .topbar, .goal-row, .input-row, .modal-card, .start-card { touch-action: manipulation; }
#word-input, #nickname-input { -webkit-user-select: text; user-select: text; touch-action: auto; }

.boot-screen { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 24px; color: var(--ink); background: radial-gradient(circle at 50% 18%, rgba(239,213,129,.66), transparent 24rem), var(--paper); }
.boot-card { display: grid; justify-items: center; gap: 16px; font-family: var(--gse-font-display); font-size: 13px; font-weight: 700; text-align: center; }
.boot-card .brand-mark { width: 52px; height: 52px; border-radius: 16px; font-size: 27px; }
.boot-card p { margin: 0; }
body:not(.is-booting) .boot-screen { display: none; }

.game-shell {
  height: 100dvh;
  min-height: 0;
  padding: clamp(8px, 2vw, 28px);
  display: grid;
  place-items: center;
}

.game-card {
  width: min(1080px, 100%);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid #ddd6bd;
  border-radius: 28px;
  background: rgba(252, 247, 236, .97);
  box-shadow: 0 28px 80px rgba(35, 59, 56, .14);
}

.topbar {
  height: 80px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.topbar-brand-group { min-width: 0; display: flex; align-items: center; gap: 16px; }
.brand { min-width: 0; display: flex; gap: 10px; align-items: center; color: inherit; font-family: var(--gse-font-display); font-weight: 700; font-size: 16px; text-decoration: none; }
.brand-name { white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 33px; height: 33px; border: 2px solid var(--ink); border-radius: 8px; color: var(--paper-light); font-size: 19px; background: var(--ink); box-shadow: 0 4px 0 rgba(35, 59, 56, .12); transform: rotate(-4deg); }
.catalog-link { flex: 0 0 auto; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 10px; font-weight: 800; text-decoration: none; transition: .18s; }
.catalog-link:hover { border-color: var(--ink); color: var(--ink); background: var(--paper-light); }
.topbar-actions { display: flex; gap: 8px; }
.icon-button { width: 38px; height: 38px; border: 1px solid #c8c9b6; border-radius: 50%; color: var(--muted); font-size: 24px; line-height: 1; background: transparent; transition: .2s; }
.icon-button:hover { color: var(--ink); border-color: var(--ink); background: #fff7e8; transform: rotate(-20deg); }
.sound-button { font-size: 17px; }.sound-button:hover { transform: translateY(-2px); }.sound-button.is-muted { color: #8e8aa9; }

.game-layout { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 290px; overflow: hidden; }
.board-panel { position: relative; min-height: 0; padding: 34px 36px 36px; }
.side-panel { min-height: 0; padding: 34px 28px; overflow-y: auto; border-left: 1px solid var(--line); background: rgba(244, 234, 215, .48); }

.goal-row, .modifier-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }.round-meta { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: stretch; gap: 8px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1, h2 { margin: 0; font-family: var(--gse-font-display); }
h1 { font-size: clamp(19px, 3vw, 25px); line-height: 1.35; }
h1 span { color: var(--yellow); }
h2 { font-size: 15px; }

.timer { min-width: 86px; padding: 8px 10px 7px; border: 1px solid #d5dac6; border-radius: 12px; text-align: right; background: #f0f2e4; }
.timer-label { display: block; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.timer strong { font-family: var(--gse-font-display); font-size: 17px; font-weight: 700; }
.timer.is-low strong { color: var(--coral); }
.game-stat { min-width: 72px; padding: 8px 10px 7px; border-radius: 12px; text-align: right; background: #e7dfcb; }.game-stat strong { color: var(--ink); font-family: var(--gse-font-display); font-size: 16px; }
.health-indicator { min-width: 92px; padding: 8px 10px 7px; border-radius: 12px; text-align: right; background: var(--coral-light); }.health-indicator strong { color: #b75643; font-family: var(--gse-font-display); font-size: 16px; letter-spacing: .06em; }.is-hidden { display: none !important; }

.progress-wrap { margin: 22px 0 25px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; color: var(--ink); font-size: 12px; font-weight: 800; }
.progress-track { height: 9px; overflow: hidden; border-radius: 10px; background: #e0dcc6; }
.progress-fill { width: 0; height: 100%; border-radius: inherit; background: var(--coral); box-shadow: none; transition: width .3s ease; }

.board {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(7, var(--cell-size));
  gap: var(--cell-gap);
}

.cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid #e2d8bd;
  border-radius: 12px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--gse-font-display);
  font-size: clamp(17px, 3vw, 23px);
  font-weight: 700;
  background: #eee6d3;
  box-shadow: 0 3px 0 #d6cdb1;
  transition: transform .2s ease, opacity .2s ease, filter .2s ease;
}
.cell::after { content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit; background: linear-gradient(135deg, rgba(255,255,255,.38), transparent 42%); }
.cell:nth-child(3n + 1) { background: #e9e1cc; }
.cell:nth-child(3n + 2) { background: #edf0df; }
.cell.has-star { border-color: #d7c36f; background: #f2e5b4; box-shadow: 0 3px 0 #ddcb88; }
.star { position: absolute; right: 5px; top: 3px; color: var(--yellow); font-size: clamp(11px, 2vw, 15px); filter: drop-shadow(0 1px 2px rgba(67,42,6,.45)); }
.cell.is-found { filter: brightness(1.42); transform: translateY(-3px) scale(1.05); z-index: 2; }
.cell.is-destroying { opacity: 0; transform: scale(.15) rotate(15deg); filter: brightness(2); }
.cell.is-hinted { animation: pulse 1s ease-in-out 2; outline: 3px solid var(--yellow); outline-offset: 2px; z-index: 2; }
.cell.is-falling { z-index: 3; will-change: transform, opacity; }
.board.is-falling-mode {
  --fall-row-step: calc(var(--cell-size) + var(--cell-gap));
  position: relative;
  padding: var(--cell-gap);
  overflow: hidden;
  border: 1px solid #ddd6bd;
  border-bottom-color: rgba(236, 119, 91, .6);
  border-radius: 20px;
  background:
    linear-gradient(to top, rgba(236, 119, 91, .1), transparent 28%),
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(var(--fall-row-step) - 1px),
      rgba(35, 59, 56, .07) calc(var(--fall-row-step) - 1px),
      rgba(35, 59, 56, .07) var(--fall-row-step)
    ),
    rgba(244, 234, 215, .54);
  box-shadow: none;
  cursor: text;
}
.board.is-falling-mode .cell { background: #eee6d3; box-shadow: none; }
.board.is-falling-mode .cell.is-empty { color: transparent; border-color: transparent; background: transparent; box-shadow: none; }
.board.is-falling-mode .cell.is-empty::after { display: none; }
.board.is-falling-mode .cell.is-active-word {
  z-index: 3;
  color: var(--ink);
  border-color: #d7c36f;
  background: #f2e5b4;
  box-shadow: none;
  transition: color .16s ease, border-color .16s ease, background .16s ease;
  will-change: transform;
}
.board.is-falling-mode .cell.is-active-word::after { display: none; }
.board.is-falling-mode .cell.is-active-word.is-typed-correct {
  color: var(--mint-dark);
  border-color: #8db899;
  background: #d9e9d2;
  box-shadow: none;
}
.board.is-falling-mode .cell.is-active-word.is-typed-wrong {
  color: #8d4e3d;
  border-color: var(--coral);
  background: var(--coral-light);
  box-shadow: none;
}
.word-heart { position: absolute; right: 4px; top: 3px; color: var(--coral); font-size: clamp(11px, 2vw, 15px); filter: drop-shadow(0 1px 1px rgba(67,20,40,.22)); }
@keyframes pulse { 50% { transform: scale(1.09); filter: brightness(1.45); } }

.word-form { margin: 27px auto 0; max-width: 500px; }
.word-label { display: block; margin-bottom: 8px; color: var(--ink); font-weight: 700; font-size: 13px; }
.input-row { display: flex; gap: 9px; }
#word-input { min-width: 0; flex: 1; height: 52px; padding: 0 16px; border: 1px solid var(--line); border-radius: 13px; outline: none; color: var(--ink); font-size: 17px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; background: var(--paper-light); transition: .2s; }
#word-input::placeholder { color: #8c927f; font-size: 13px; font-weight: 600; letter-spacing: 0; text-transform: none; }
#word-input:focus { border-color: var(--mint-dark); box-shadow: 0 0 0 3px rgba(56,113,92,.14); }
.submit-button { min-height: 52px; padding: 0 17px; border: 0; border-radius: 13px; color: var(--paper-light); font-weight: 800; white-space: nowrap; background: var(--ink); box-shadow: 0 3px 0 #132923; transition: transform .2s, filter .2s; }
.submit-button span { margin-left: 5px; font-size: 19px; }
.submit-button:hover { filter: brightness(1.07); transform: translateY(-2px); }
.submit-button:disabled { cursor: default; opacity: .55; transform: none; }
.message { max-width: 500px; min-height: 20px; margin: 9px auto 0; padding: 0 2px; color: var(--muted); font-size: 12px; font-weight: 600; }
.message.is-error { color: #b75643; }.message.is-success { color: var(--mint-dark); }

.is-falling-mode .word-form {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.is-falling-mode .message { margin-top: 12px; text-align: center; }

.rule-card, .modifier-card, .hint-card, .dev-card, .leaderboard-card { padding: 17px; border: 1px solid var(--line); border-radius: 17px; background: rgba(252,247,236,.76); }
.rule-card { display: flex; gap: 12px; }.rule-card p:not(.eyebrow), .modifier-card > p, .hint-card > p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.rule-icon { flex: 0 0 28px; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; }.star-icon { color: #6d4c17; background: var(--yellow); }
.modifier-card { margin-top: 16px; }.modifier-badge { padding: 5px 7px; border-radius: 7px; color: var(--mint-dark); font-size: 9px; font-weight: 800; letter-spacing: .08em; background: #d9e9d2; }.modifier-badge.is-danger { color: #8d4e3d; background: var(--coral-light); }
.text-button { margin-top: 12px; padding: 0; border: 0; color: var(--mint-dark); font-size: 12px; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; background: transparent; }
.hint-card { margin-top: 16px; border-style: dashed; }
.hint-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.hint-button { flex: 0 0 40px; width: 40px; height: 40px; padding: 0; border: 1px solid #d7c36f; border-radius: 12px; color: #635c37; font-size: 20px; line-height: 1; background: var(--yellow); box-shadow: 0 3px 0 #ddcb88; transition: transform .2s, filter .2s; }
.hint-button:hover { filter: brightness(1.08); transform: translateY(-2px); }.hint-button:disabled { cursor: default; opacity: .55; transform: none; }
.dev-card { margin-top: 16px; border-color: #b7cdbb; background: rgba(177,217,191,.2); }
.dev-card label { display: block; margin-bottom: 8px; color: var(--ink); font-size: 12px; font-weight: 700; }
.dev-card select { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; outline: none; color: var(--ink); font-size: 12px; font-weight: 700; background: var(--paper-light); }
.dev-card select:focus { border-color: var(--mint-dark); box-shadow: 0 0 0 3px rgba(56,113,92,.14); }
#word-preset-setting, #recovery-frequency-setting, #word-density-setting { margin-top: 13px; }.dev-card #recovery-frequency-setting p { margin: 7px 0 0; color: var(--muted); font-size: 10px; line-height: 1.4; }
.developer-words-label { margin: 15px 0 7px; color: var(--ink); font-size: 12px; font-weight: 700; }
.developer-words { min-height: 26px; display: flex; flex-wrap: wrap; gap: 6px; }.developer-word { padding: 4px 6px; border-radius: 6px; color: #635c37; font-family: var(--gse-font-display); font-size: 9px; font-weight: 700; background: #efe2b7; }.developer-words-empty { color: var(--muted); font-size: 11px; }
.debug-details { margin-top: 17px; }.debug-details summary { cursor: pointer; color: var(--ink); font-size: 12px; font-weight: 700; }.debug-log { max-height: 205px; margin: 9px 0 0; padding: 0; overflow: auto; list-style: none; }.debug-log li { padding: 7px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; line-height: 1.45; }.debug-log li:last-child { border-bottom: 0; }.debug-log time { display: inline-block; min-width: 31px; margin-right: 5px; color: var(--mint-dark); font-family: var(--gse-font-display); font-size: 8px; }.debug-log-empty { color: var(--muted); }
.leaderboard-card { margin-top: 16px; border-color: #d7cda9; }.leaderboard-table { width: 100%; border-collapse: collapse; color: var(--ink); font-size: 11px; text-align: left; }.leaderboard-table th { padding: 2px 0 7px; color: var(--muted); font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }.leaderboard-table th:nth-child(3), .leaderboard-table th:nth-child(4), .leaderboard-table td:nth-child(3), .leaderboard-table td:nth-child(4) { text-align: right; }.leaderboard-table td { padding: 7px 0; border-top: 1px solid var(--line); }.leaderboard-table td:nth-child(1) { width: 24px; color: #9a7b24; font-family: var(--gse-font-display); font-size: 9px; }.leaderboard-table td:nth-child(2) { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }.leaderboard-empty { color: var(--muted); text-align: center; }

.modal { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 24px; background: rgba(29, 51, 43, .38); backdrop-filter: blur(5px); }.modal.is-hidden { display: none; }
.modal-card { position: relative; z-index: 1; width: min(390px, 100%); padding: 34px; border: 1px solid #d4ccb4; border-radius: 24px; color: var(--ink); text-align: center; background: var(--paper-light); box-shadow: 0 22px 60px rgba(35,59,56,.24); }.modal-card h2 { margin: 8px 0 12px; font-size: 21px; }.modal-card p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.65; }.result-icon { width: 62px; height: 62px; margin: 0 auto 18px; display: grid; place-items: center; border: 5px solid var(--paper-light); border-radius: 18px; color: #635c37; font-size: 33px; background: var(--yellow); box-shadow: 0 4px 16px #5b563514; transform: rotate(-8deg); }.modal-button { width: 100%; margin-top: 25px; }.leaderboard-prompt { margin-top: 19px; text-align: left; }.leaderboard-prompt label { display: block; margin-bottom: 7px; color: var(--ink); font-size: 12px; font-weight: 800; }.leaderboard-input-row { display: flex; gap: 8px; }.leaderboard-input-row input { min-width: 0; flex: 1; height: 45px; padding: 0 11px; border: 1px solid var(--line); border-radius: 10px; outline: 0; color: var(--ink); background: var(--paper); }.leaderboard-input-row input:focus { border-color: var(--mint-dark); box-shadow: 0 0 0 3px rgba(56,113,92,.13); }.leaderboard-input-row .submit-button { min-height: 45px; padding: 0 12px; font-size: 12px; }.leaderboard-save-message { min-height: 18px; margin-top: 7px !important; color: var(--mint-dark) !important; font-size: 11px !important; }
.dialog-catalog-link { display: inline-flex; min-height: 44px; margin-top: 12px; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; font-weight: 800; text-decoration: none; }
.dialog-catalog-link:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.start-screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 10%, rgba(239,213,129,.66), transparent 28rem), rgba(244,234,215,.94); backdrop-filter: blur(9px); }.start-screen.is-hidden { display: none; }.start-screen-scene { z-index: 0; }.start-card { position: relative; z-index: 1; width: min(560px, 100%); padding: clamp(28px, 6vw, 52px); border: 1px solid #d4ccb4; border-radius: 28px; color: var(--ink); text-align: center; background: var(--paper-light); box-shadow: 0 24px 80px rgba(35,59,56,.2); }.start-brand { justify-content: center; margin-bottom: 35px; }.start-card h1 { font-size: clamp(24px, 5vw, 34px); }.start-copy { max-width: 380px; margin: 15px auto 25px; color: var(--muted); font-size: 14px; line-height: 1.65; }.preset-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; text-align: left; }.preset-choice { min-height: 62px; padding: 13px; border: 1px solid var(--line); border-radius: 15px; color: var(--ink); text-align: left; background: #eee6d3; transition: .18s; }.preset-choice strong { display: block; font-size: 13px; }.preset-choice:hover, .preset-choice.is-selected { border-color: #8db899; background: #d9e9d2; color: var(--mint-dark); transform: translateY(-2px); }.preset-choice:focus-visible { outline: 3px solid var(--coral); outline-offset: 2px; }.start-button { width: 100%; margin-top: 20px; }.is-production .dev-card { display: none; }
.orientation-notice { display: none; }
.modal, .start-screen { overflow: auto; overscroll-behavior: contain; }

@media (max-width: 1100px) and (min-width: 721px) {
  .start-screen-scene .gse-cube-fragment[data-side="left"] { left: -5rem; opacity: .34; }
  .start-screen-scene .gse-cube-fragment[data-side="right"] { right: -3rem; opacity: .72; }
}

@media (max-width: 790px) {
  :root { --cell-size: clamp(34px, min(11.2vw, calc((100dvh - 330px) / 8)), 52px); }
  .game-shell { padding: 0; }
  .game-card { border: 0; border-radius: 0; }
  .game-layout { grid-template-columns: 1fr; }
  .side-panel { display: none; }
  .board-panel { padding: 25px 18px 20px; }
  .topbar { height: 66px; padding: 0 14px; }
  .topbar-brand-group { gap: 7px; }
  .brand { gap: 8px; font-size: clamp(9px, 2.6vw, 13px); }
  .brand-mark { flex: 0 0 30px; width: 30px; height: 30px; font-size: 17px; }
  .topbar-actions { gap: 5px; }
  .catalog-link { width: 32px; height: 32px; padding: 0; display: grid; place-items: center; overflow: hidden; color: transparent; font-size: 0; }
  .catalog-link::before { content: "←"; color: var(--muted); font-size: 15px; }
  .icon-button { width: 34px; height: 34px; }
}

@media (max-width: 500px) {
  .goal-row { gap: 10px; }
  .round-meta { max-width: 205px; }
  .timer { min-width: 78px; }
  .timer strong { font-size: 14px; }
  .game-stat { min-width: 66px; }
  .input-row { gap: 7px; }
  .submit-button { padding: 0 12px; font-size: 12px; }
  .submit-button span { display: none; }
  .preset-choices { grid-template-columns: 1fr; }
  .start-card { padding: 30px 22px; }
  .start-brand { margin-bottom: 25px; }
}

@media (max-width: 370px) {
  .topbar { padding: 0 11px; }
  .brand { gap: 6px; font-size: 8.5px; letter-spacing: -.025em; }
  .brand-mark { flex-basis: 28px; width: 28px; height: 28px; font-size: 16px; }
  .topbar-actions { gap: 4px; }
  .icon-button { width: 30px; height: 30px; font-size: 20px; }
  .sound-button { font-size: 15px; }
}

@media (max-height: 720px) {
  .topbar { height: 64px; }
  .board-panel { padding-top: 18px; padding-bottom: 16px; }
  .progress-wrap { margin: 13px 0 15px; }
  .word-form { margin-top: 16px; }
  .word-label { margin-bottom: 5px; }
  .start-card { padding: 22px; }
  .start-brand { margin-bottom: 18px; }
  .start-copy { margin: 10px auto 15px; }
}

@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
  .orientation-notice { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; gap: 14px; padding: 28px; color: var(--ink); text-align: center; background: var(--paper); }
  .orientation-notice span { color: var(--yellow); font-size: 54px; }
  .orientation-notice p { max-width: 260px; margin: 0; font-family: var(--gse-font-display); font-size: 15px; line-height: 1.55; }
}
