:root {
  --page-bg: #fcf6ea;
  --page-bg-deep: #f4ecdc;
  --panel: rgba(255, 250, 240, 0.88);
  --panel-strong: rgba(255, 252, 247, 0.96);
  --ink: #162033;
  --ink-soft: #586171;
  --line: rgba(22, 32, 51, 0.12);
  --line-strong: rgba(22, 32, 51, 0.28);
  --accent: #ef7a4d;
  --accent-strong: #d25724;
  --mint: #2a8c78;
  --mint-soft: rgba(42, 140, 120, 0.16);
  --blueprint: rgba(55, 118, 188, 0.12);
  --sun: rgba(239, 122, 77, 0.14);
  --warning: #c1512c;
  --warning-bg: rgba(193, 81, 44, 0.12);
  --success: #1f7a61;
  --success-bg: rgba(31, 122, 97, 0.12);
  --shadow: 0 28px 70px rgba(28, 34, 44, 0.12);
  --board-stroke: #243349;
  --cage-stroke: #d25724;
  --given-bg: rgba(31, 122, 97, 0.12);
  --selected-bg: rgba(42, 140, 120, 0.2);
  --related-bg: rgba(55, 118, 188, 0.1);
  --conflict-bg: rgba(193, 81, 44, 0.16);
  --mistake-ring: rgba(193, 81, 44, 0.85);
  --content: min(1360px, calc(100% - 26px));
  --cell-size: clamp(2.55rem, 8vw, 4.1rem);
  --radius: 28px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, var(--sun), transparent 24%),
    radial-gradient(circle at 80% 10%, rgba(42, 140, 120, 0.14), transparent 22%),
    linear-gradient(180deg, var(--page-bg) 0%, var(--page-bg-deep) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--blueprint) 1px, transparent 1px),
    linear-gradient(90deg, var(--blueprint) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.45;
}

a {
  color: inherit;
}

button {
  font: inherit;
}

button,
.mini-link,
.site-links a {
  touch-action: manipulation;
}

.site-shell {
  position: relative;
  z-index: 1;
}

.site-nav {
  width: var(--content);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
}

.site-brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background:
    linear-gradient(140deg, rgba(239, 122, 77, 1) 0%, rgba(42, 140, 120, 0.9) 100%);
  box-shadow: 0 14px 30px rgba(42, 140, 120, 0.18);
  position: relative;
}

.site-brand-mark::before,
.site-brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 10px;
}

.site-brand-mark::before {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.92) 45%, transparent 45%, transparent 55%, rgba(255, 255, 255, 0.92) 55%),
    linear-gradient(rgba(255, 255, 255, 0.92) 45%, transparent 45%, transparent 55%, rgba(255, 255, 255, 0.92) 55%);
  opacity: 0.9;
}

.site-brand-mark::after {
  inset: 15px;
  border-radius: 8px;
  border: 2px solid rgba(22, 32, 51, 0.16);
}

.site-brand-label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--mint);
  font-weight: 800;
}

.site-brand-name {
  display: block;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: 1.2rem;
  font-weight: 700;
}

.site-links {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.site-links a,
.mini-link {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
  border-radius: 999px;
  padding: 11px 15px;
  text-decoration: none;
  color: var(--ink-soft);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.site-links a:hover,
.site-links a:focus-visible,
.mini-link:hover,
.mini-link:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(42, 140, 120, 0.32);
  background: rgba(255, 255, 255, 0.88);
  outline: none;
}

.mini-link {
  cursor: pointer;
}

.page {
  width: var(--content);
  margin: 0 auto;
  padding-bottom: calc(34px + env(safe-area-inset-bottom, 0px));
}

.hero,
.toolbar-panel,
.stage-card,
.info-card {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.hero {
  border-radius: var(--radius);
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.9fr);
  gap: 24px;
}

.hero-copy h1,
.stage-header h2,
.info-card h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero-copy h1 {
  font-size: clamp(2.2rem, 4vw, 3.8rem);
}

.eyebrow,
.toolbar-label,
.hero-label {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--mint);
}

.hero-lead,
.panel-description,
.detail-copy,
.hero-help,
.message-text {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.55;
}

.hero-panel {
  border-radius: 22px;
  background:
    radial-gradient(circle at top right, rgba(42, 140, 120, 0.12), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 250, 244, 0.78));
  border: 1px solid rgba(42, 140, 120, 0.12);
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.hero-stat {
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(252, 249, 243, 0.9);
  border: 1px solid rgba(22, 32, 51, 0.08);
}

.hero-stat strong {
  font-size: 1.1rem;
}

.toolbar-panel {
  margin-top: 18px;
  border-radius: 24px;
  padding: 20px 22px;
  display: grid;
  gap: 20px;
}

.toolbar-group {
  display: grid;
  gap: 10px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.mode-pill,
.action-pill {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.mode-pill:hover,
.mode-pill:focus-visible,
.action-pill:hover,
.action-pill:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(42, 140, 120, 0.3);
  outline: none;
}

.mode-pill.is-active,
.action-pill.is-active {
  background: linear-gradient(135deg, rgba(42, 140, 120, 0.16), rgba(239, 122, 77, 0.12));
  color: var(--ink);
  border-color: rgba(42, 140, 120, 0.36);
}

.action-pill-strong {
  background: linear-gradient(135deg, var(--mint) 0%, #58a493 100%);
  color: white;
  border-color: transparent;
}

.workspace {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.stage-card,
.info-card {
  border-radius: 26px;
  padding: 22px;
}

.session-note {
  margin: 2px 2px 0;
  color: var(--ink-soft);
  line-height: 1.45;
  font-size: 0.95rem;
}

.stage-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.status-badge {
  align-self: start;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  background: rgba(55, 118, 188, 0.12);
  color: #30567f;
}

.status-badge.is-warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.status-badge.is-success {
  background: var(--success-bg);
  color: var(--success);
}

.panel-description,
.message-text {
  margin-top: 10px;
}

.message-text {
  min-height: 1.5em;
}

.message-text.is-warning {
  color: var(--warning);
}

.message-text.is-success {
  color: var(--success);
}

.board-wrap {
  margin-top: 20px;
  position: relative;
  border-radius: 26px;
  padding: 16px;
  background:
    radial-gradient(circle at top left, rgba(239, 122, 77, 0.08), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(250, 245, 236, 0.78));
  border: 1px solid rgba(22, 32, 51, 0.08);
}

.loading-overlay {
  position: absolute;
  inset: 16px;
  z-index: 3;
  display: grid;
  place-items: center;
  border-radius: 20px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(252, 249, 243, 0.82);
  backdrop-filter: blur(10px);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols, 9), minmax(0, 1fr));
  gap: 0;
  width: min(100%, calc(var(--cell-size) * var(--cols, 9)));
  margin: 0 auto;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid rgba(22, 32, 51, 0.12);
  touch-action: manipulation;
}

.board[data-mode="sudoku"],
.board[data-mode="killer"] {
  aspect-ratio: 1;
}

.board[data-mode="kakuro"] {
  width: min(100%, calc(var(--cell-size) * 8));
  aspect-ratio: 1;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
}

.cell--play {
  appearance: none;
  border: 1px solid rgba(22, 32, 51, 0.12);
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  padding: 0;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

.cell--play:hover,
.cell--play:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.98);
}

.cell--play.is-related {
  background: var(--related-bg);
}

.cell--play.is-selected {
  background: var(--selected-bg);
  box-shadow: inset 0 0 0 3px rgba(42, 140, 120, 0.58);
  z-index: 1;
}

.cell--play.is-given {
  background: var(--given-bg);
}

.cell--play.is-conflict {
  background: var(--conflict-bg);
}

.cell--play.is-mistake {
  box-shadow: inset 0 0 0 3px var(--mistake-ring);
}

.cell--play.is-box-top {
  border-top: 3px solid var(--board-stroke);
}

.cell--play.is-box-right {
  border-right: 3px solid var(--board-stroke);
}

.cell--play.is-box-bottom {
  border-bottom: 3px solid var(--board-stroke);
}

.cell--play.is-box-left {
  border-left: 3px solid var(--board-stroke);
}

.cell--play.cell--killer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-top: var(--cage-top, 0px) solid var(--cage-stroke);
  border-right: var(--cage-right, 0px) solid var(--cage-stroke);
  border-bottom: var(--cage-bottom, 0px) solid var(--cage-stroke);
  border-left: var(--cage-left, 0px) solid var(--cage-stroke);
}

.cell-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(1.1rem, 2vw, 1.95rem);
  font-weight: 700;
  line-height: 1;
}

.cell-value.is-given {
  color: var(--mint);
}

.cell-notes {
  position: absolute;
  inset: 5px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 1px;
  align-items: center;
  justify-items: center;
  color: rgba(22, 32, 51, 0.72);
}

.note-digit {
  font-size: clamp(0.45rem, 1vw, 0.62rem);
  line-height: 1;
}

.cage-sum {
  position: absolute;
  top: 4px;
  left: 5px;
  font-size: 0.58rem;
  line-height: 1;
  color: var(--accent-strong);
  font-weight: 800;
  pointer-events: none;
}

.cell--clue {
  border: 1px solid rgba(22, 32, 51, 0.16);
  background:
    linear-gradient(180deg, rgba(33, 45, 63, 0.96), rgba(17, 24, 39, 0.96));
  overflow: hidden;
}

.cell--clue::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 47%, rgba(252, 249, 243, 0.85) 49%, rgba(252, 249, 243, 0.85) 51%, transparent 53%);
}

.clue-value {
  position: absolute;
  z-index: 1;
  font-size: clamp(0.55rem, 1vw, 0.75rem);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.88);
}

.clue-value-down {
  top: 8%;
  right: 12%;
}

.clue-value-across {
  bottom: 8%;
  left: 12%;
}

.keypad {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.keypad-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  border-radius: 18px;
  min-height: 50px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.keypad-btn:hover,
.keypad-btn:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(42, 140, 120, 0.32);
  outline: none;
}

.keypad-btn-clear {
  grid-column: span 2;
  background: rgba(239, 122, 77, 0.12);
}

.side-panel {
  display: grid;
  gap: 18px;
}

.rule-list {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--ink-soft);
  line-height: 1.55;
}

.rule-list li + li {
  margin-top: 8px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
  margin: 14px 0 0;
}

.meta-grid div {
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(22, 32, 51, 0.08);
}

.meta-grid dt {
  margin: 0 0 4px;
  font-size: 0.74rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.meta-grid dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.game-footer {
  padding: 18px 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--ink-soft);
}

.game-footer-links {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

html[data-display-mode="standalone"] .site-links [data-install-button],
html[data-display-mode="standalone"] .game-footer {
  display: none;
}

html[data-display-mode="standalone"] .site-nav {
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}

html[data-display-mode="standalone"] .page {
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

html[data-display-mode="standalone"] .hero-lead,
html[data-display-mode="standalone"] .hero-help,
html[data-display-mode="standalone"] .session-note,
html[data-display-mode="standalone"] .side-panel {
  display: none;
}

@media (max-width: 1080px) {
  .hero,
  .workspace {
    grid-template-columns: 1fr;
  }

  .hero-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  :root {
    --content: min(100%, calc(100% - 12px));
    --cell-size: clamp(2.35rem, 11vw, 3.35rem);
  }

  .site-nav,
  .page {
    width: var(--content);
  }

  .site-nav {
    padding-top: 10px;
    gap: 10px;
  }

  .site-links {
    width: 100%;
    gap: 8px;
  }

  .hero,
  .toolbar-panel,
  .stage-card,
  .info-card {
    border-radius: 22px;
  }

  .hero,
  .toolbar-panel,
  .stage-card,
  .info-card {
    padding: 16px;
  }

  .page {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .hero {
    order: 1;
    gap: 14px;
  }

  .workspace {
    display: contents;
  }

  .play-area {
    order: 2;
  }

  .toolbar-panel {
    order: 3;
    margin-top: 0;
    gap: 14px;
  }

  .side-panel {
    order: 4;
  }

  .game-footer {
    order: 5;
  }

  .hero-copy h1 {
    font-size: clamp(2rem, 10vw, 2.8rem);
  }

  .hero-lead,
  .hero-help,
  .session-note,
  .side-panel {
    display: none;
  }

  .hero-lead {
    font-size: 0.98rem;
    line-height: 1.45;
  }

  .hero-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    padding: 14px;
  }

  .hero-stat {
    padding: 10px 12px;
    border-radius: 16px;
  }

  .hero-stat strong {
    font-size: 0.98rem;
    line-height: 1.15;
  }

  .hero-label {
    margin-bottom: 6px;
    font-size: 0.64rem;
    letter-spacing: 0.16em;
  }

  .pill-row {
    gap: 8px;
  }

  .toolbar-group-actions .pill-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar-group-actions .action-pill-strong {
    grid-column: span 2;
  }

  .toolbar-group {
    gap: 8px;
  }

  .session-note {
    font-size: 0.86rem;
    line-height: 1.4;
  }

  .stage-card,
  .info-card {
    padding: 16px;
  }

  .stage-header {
    align-items: center;
    gap: 12px;
  }

  .status-badge {
    padding: 8px 12px;
    font-size: 0.76rem;
  }

  .panel-description,
  .message-text {
    margin-top: 6px;
    font-size: 0.94rem;
    line-height: 1.45;
  }

  .board-wrap {
    margin-top: 14px;
    padding: 10px;
  }

  .board {
    width: 100%;
    max-width: none;
  }

  .board[data-mode="kakuro"] {
    width: 100%;
  }

  .keypad {
    margin-top: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .keypad-btn-clear {
    grid-column: span 3;
  }

  .keypad-btn {
    min-height: 48px;
  }

  .cage-sum {
    top: 3px;
    left: 4px;
    font-size: 0.64rem;
  }

  .clue-value {
    font-size: 0.68rem;
  }

  .detail-copy,
  .rule-list {
    font-size: 0.94rem;
    line-height: 1.45;
  }

  .rule-list {
    margin-top: 10px;
  }

  .side-panel {
    gap: 12px;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .meta-grid div {
    padding: 10px 12px;
  }
}
