:root {
  --bg: #a5f29d;
  --bg-dark: #79e66f;
  --ink: #111827;
  --muted: #5a6472;
  --panel: rgba(255, 255, 255, .94);
  --line: #1a2636;
  --primary: #e93434;
  --primary-dark: #c92323;
  --accent: #ffd24a;
  --selected: #fff3a9;
  --correct: #b9f4c8;
  --wrong: #ffc9c9;
  --cell: #a5f29d;
  --shadow: 0 12px 32px rgba(27, 64, 35, .15);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP",
    "Noto Sans Devanagari", "Noto Sans Thai", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 2%, rgba(255,255,255,.35), transparent 28%),
    linear-gradient(145deg, #b6f7ae 0%, var(--bg) 46%, #8de987 100%);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  color: #fff;
  background: rgba(23, 54, 30, .94);
  backdrop-filter: blur(12px);
  box-shadow: 0 5px 18px rgba(0,0,0,.18);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 45px;
  height: 45px;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, #e93434, #a91515);
  border: 2px solid #ffd24a;
  font-size: 1.5rem;
  font-weight: 900;
}
.topbar h1 { margin: 0; font-size: 1.3rem; }
.eyebrow {
  margin: 0 0 2px;
  font-size: .69rem;
  font-weight: 900;
  letter-spacing: .13em;
  opacity: .75;
}
.eyebrow.dark { color: #596171; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-button, .install-button {
  min-height: 40px;
  border-radius: 11px;
  color: #fff;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  font-weight: 800;
}
.icon-button { width: 42px; }
.install-button { padding: 7px 12px; }

.page {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 20px 18px 40px;
}
.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
  padding: 20px 22px;
  border-radius: 22px;
  background: rgba(255,255,255,.55);
  border: 1px solid rgba(255,255,255,.68);
}
.level-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  color: #fff;
  background: #17361e;
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .08em;
}
.hero h2 {
  margin: 5px 0 2px;
  color: var(--primary);
  font-size: clamp(1.55rem, 3vw, 2.25rem);
  line-height: 1.2;
}
.hero p { margin: 0; color: #34403a; }
.score-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(78px, 1fr));
  gap: 8px;
  min-width: 315px;
}
.score-panel div {
  padding: 10px 12px;
  border-radius: 14px;
  text-align: center;
  background: rgba(255,255,255,.82);
}
.score-panel span, .record-grid span, .complete-stats span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
}
.score-panel strong { font-size: 1.25rem; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(360px, .9fr);
  gap: 16px;
}
.board-column, .clue-column { display: grid; align-content: start; gap: 16px; }
.panel {
  padding: 18px;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-heading h3, .help-panel h3, .record-panel h3 {
  margin: 0;
  font-size: 1.05rem;
}
.small-button {
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  color: #17361e;
  background: #ddf9df;
  font-weight: 800;
}
.crossword-board {
  --cols: 12;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  width: min(100%, 690px);
  margin: 0 auto;
  border: 3px solid var(--line);
  background: var(--line);
  gap: 1px;
  aspect-ratio: 12 / 7;
  touch-action: manipulation;
  user-select: none;
}
.cell, .block-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
}
.block-cell { background: #050505; }
.cell {
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  color: #0b1017;
  background: var(--cell);
  font-weight: 900;
  font-size: clamp(.82rem, 3.2vw, 1.45rem);
  text-transform: uppercase;
}
.cell:hover { filter: brightness(1.04); }
.cell.selected { background: var(--selected); }
.cell.active {
  outline: 4px solid #f03e3e;
  outline-offset: -4px;
  z-index: 2;
}
.cell.correct { background: var(--correct); }
.cell.wrong { background: var(--wrong); animation: shake .25s linear; }
.cell.revealed::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e0a100;
}
.cell-number {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: clamp(.45rem, 1.6vw, .65rem);
  font-weight: 900;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  35% { transform: translateX(-3px); }
  70% { transform: translateX(3px); }
}
.selected-clue {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 14px auto 0;
  width: min(100%, 690px);
  padding: 12px 14px;
  border-radius: 14px;
  background: #f5f7fb;
}
.selected-clue > span {
  display: grid;
  place-items: center;
  min-width: 42px;
  height: 42px;
  border-radius: 12px;
  color: #fff;
  background: #17361e;
  font-weight: 900;
}
.selected-clue p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.game-buttons {
  display: grid;
  grid-template-columns: 1fr 1.3fr .75fr;
  gap: 9px;
  margin: 13px auto 0;
  width: min(100%, 690px);
}
.primary-button, .secondary-button, .danger-button {
  min-height: 45px;
  padding: 10px 13px;
  border: 0;
  border-radius: 12px;
  font-weight: 900;
}
.primary-button { color: #fff; background: var(--primary); }
.primary-button:hover { background: var(--primary-dark); }
.secondary-button { color: #213128; background: #e8f2e9; }
.danger-button { width: 100%; color: #a82323; background: #fee8e8; }

.keyboard-panel { padding-top: 14px; }
.keyboard-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.keyboard-title span { color: var(--muted); font-size: .78rem; }
.virtual-keyboard {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 5px;
}
.key {
  min-height: 39px;
  border: 1px solid #cbd3df;
  border-radius: 8px;
  color: #17211b;
  background: #fff;
  font-weight: 900;
  box-shadow: 0 2px 0 #bac4d0;
}
.key:active { transform: translateY(1px); box-shadow: 0 1px 0 #bac4d0; }
.keyboard-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 8px;
}
.control-key { background: #f0f4f8; }

select {
  min-height: 40px;
  padding: 7px 9px;
  border: 1px solid #cbd2dc;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.clue-table-wrap { overflow-x: auto; }
.clue-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}
.clue-table th, .clue-table td {
  padding: 9px 8px;
  border-bottom: 1px dotted #64706b;
  text-align: left;
  vertical-align: middle;
}
.clue-table th { font-size: .78rem; }
.clue-row {
  cursor: pointer;
  transition: .15s;
}
.clue-row:hover { background: #eef9ee; }
.clue-row.selected { background: #fff4bd; }
.clue-row.completed { background: #e3f8e8; }
.clue-number { white-space: nowrap; font-weight: 900; }
.clue-answer { font-weight: 900; letter-spacing: .02em; }
.clue-answer.masked { letter-spacing: .15em; }
.focus-muted { opacity: .28; }

.help-panel ol { margin: 9px 0 8px; padding-left: 1.35rem; }
.help-panel li { margin: 5px 0; }
.help-panel p { margin: 8px 0 0; color: var(--muted); font-size: .86rem; }
.record-grid, .complete-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.record-grid div, .complete-stats div {
  padding: 10px 8px;
  border-radius: 12px;
  text-align: center;
  background: #f4f6f8;
}
.record-grid strong, .complete-stats strong { font-size: 1.08rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 60;
  transform: translate(-50%, 20px);
  max-width: min(90vw, 520px);
  padding: 11px 17px;
  border-radius: 999px;
  color: #fff;
  background: #17211b;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  opacity: 0;
  pointer-events: none;
  transition: .22s;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.complete-dialog {
  width: min(92vw, 480px);
  padding: 28px;
  border: 0;
  border-radius: 22px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,.35);
}
.complete-dialog::backdrop { background: rgba(4,13,7,.68); }
.celebration { font-size: 3.2rem; }
.complete-dialog h2 { margin: 5px 0; }
.complete-dialog > p:last-of-type { color: var(--muted); }
.complete-stats { grid-template-columns: 1fr 1fr; }
.complete-stats strong { font-size: 1.45rem; }
.dialog-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

@media (max-width: 940px) {
  .game-layout { grid-template-columns: 1fr; }
  .clue-column { grid-template-columns: 1fr; }
}
@media (max-width: 650px) {
  .page { padding: 12px 10px 28px; }
  .topbar h1 { font-size: 1.03rem; }
  .brand-mark { width: 39px; height: 39px; }
  .install-button { display: none !important; }
  .hero { display: block; padding: 15px; }
  .hero p { font-size: .86rem; }
  .score-panel { min-width: 0; margin-top: 12px; }
  .panel { padding: 13px; border-radius: 16px; }
  .crossword-board { width: 100%; }
  .game-buttons { grid-template-columns: 1fr 1fr; }
  .game-buttons #clearButton { grid-column: 1 / -1; }
  .virtual-keyboard { grid-template-columns: repeat(9, 1fr); gap: 4px; }
  .key { min-height: 38px; }
  .keyboard-title { display: block; }
  .keyboard-title span { display: block; margin-top: 2px; }
}
@media (max-width: 390px) {
  .score-panel { gap: 5px; }
  .score-panel div { padding: 8px 5px; }
  .score-panel strong { font-size: 1.05rem; }
  .selected-clue { padding: 9px; }
  .selected-clue > span { min-width: 36px; height: 36px; }
}
