:root {
  color-scheme: light;
  --paper: #f7f3eb;
  --paper-strong: #fffdf8;
  --ink: #1d2328;
  --muted: #65717a;
  --line: #d9d0c4;
  --red: #b3382d;
  --red-strong: #94291f;
  --teal: #157a72;
  --teal-soft: #d9f0ed;
  --gold: #c48a1b;
  --gold-soft: #f6e6bd;
  --shadow: 0 18px 55px rgba(38, 35, 30, 0.12);
  --radius: 8px;
  font-family:
    "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, -apple-system,
    BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(179, 56, 45, 0.08), transparent 32%),
    linear-gradient(240deg, rgba(21, 122, 114, 0.11), transparent 36%),
    var(--paper);
  color: var(--ink);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.site-footer {
  margin-top: 22px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  color: var(--muted);
  font-size: 0.82rem;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
  font-weight: 800;
}

.site-footer a:hover {
  color: var(--red);
}

.topbar,
.round-header,
.panel-heading,
.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar {
  margin-bottom: 20px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p,
dl,
dd {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.6rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  line-height: 1.35;
  letter-spacing: 0;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.65;
}

.legal-layout {
  max-width: 900px;
}

.legal-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.legal-panel {
  border: 1px solid rgba(29, 35, 40, 0.1);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.86);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 18px;
}

.legal-panel section {
  display: grid;
  gap: 8px;
}

.legal-panel p {
  color: var(--muted);
  line-height: 1.75;
}

.contact-placeholder {
  border: 1px solid rgba(21, 122, 114, 0.18);
  border-radius: var(--radius);
  background: var(--teal-soft);
  color: var(--teal) !important;
  padding: 10px 12px;
  font-weight: 900;
}

.contact-placeholder a {
  color: inherit;
  text-decoration: none;
}

.contact-placeholder a:hover {
  text-decoration: underline;
}

.top-actions,
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-button,
.primary-button,
.ghost-button,
.text-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 42px;
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

.mode-button {
  min-width: 72px;
  padding: 0 16px;
  background: rgba(255, 253, 248, 0.72);
  color: var(--ink);
  font-weight: 800;
}

.mode-button.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper-strong);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 18px;
  align-items: start;
}

.board-zone,
.status-panel,
.history-panel,
.hint-panel,
.found-panel {
  border: 1px solid rgba(29, 35, 40, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.84);
  box-shadow: var(--shadow);
}

.board-zone {
  padding: clamp(16px, 3vw, 28px);
}

.score-box {
  min-width: 96px;
  border-left: 4px solid var(--red);
  padding-left: 12px;
  text-align: right;
}

.score-box span {
  display: block;
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.score-box small {
  color: var(--muted);
  font-weight: 700;
}

.board {
  width: min(78vw, 520px);
  max-width: 100%;
  aspect-ratio: 1;
  margin: 22px auto 16px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(8px, 1.6vw, 12px);
  touch-action: none;
}

.tile {
  border: 1px solid rgba(29, 35, 40, 0.16);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.75), transparent 34%),
    #fffaf0;
  color: var(--ink);
  box-shadow:
    inset 0 -8px 0 rgba(29, 35, 40, 0.04),
    0 10px 18px rgba(33, 26, 21, 0.08);
  font-size: clamp(1.55rem, 9vw, 3.2rem);
  font-weight: 900;
  line-height: 1;
  display: grid;
  place-items: center;
  user-select: none;
}

.tile.is-selected {
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.55), transparent 34%),
    var(--teal);
  border-color: #0f635d;
  color: white;
  transform: translateY(-2px);
}

.tile.is-last {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.tile:focus-visible,
.mode-button:focus-visible,
.primary-button:focus-visible,
.ghost-button:focus-visible,
.text-button:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid rgba(21, 122, 114, 0.32);
  outline-offset: 2px;
}

.word-tray {
  min-height: 62px;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(247, 243, 235, 0.8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.current-word {
  font-size: clamp(1.15rem, 5vw, 1.75rem);
  font-weight: 900;
  white-space: nowrap;
}

.word-status {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
  text-align: right;
}

.controls {
  margin-top: 12px;
}

.primary-button,
.ghost-button {
  flex: 1 1 112px;
  padding: 0 14px;
  font-weight: 900;
}

.primary-button {
  border-color: var(--red);
  background: var(--red);
  color: white;
}

.primary-button:hover {
  background: var(--red-strong);
}

.ghost-button {
  background: var(--paper-strong);
  color: var(--ink);
}

.ghost-button:hover,
.mode-button:hover,
.text-button:hover,
.store-item:hover {
  transform: translateY(-1px);
}

.progress-wrap {
  margin-top: 16px;
}

.progress-track {
  height: 12px;
  border: 1px solid rgba(29, 35, 40, 0.13);
  border-radius: 999px;
  overflow: hidden;
  background: #efe7dc;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 180ms ease;
}

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

.status-panel,
.history-panel,
.hint-panel,
.found-panel {
  padding: 16px;
}

.text-button {
  min-height: 34px;
  padding: 0 10px;
  border-color: rgba(29, 35, 40, 0.18);
  background: transparent;
  color: var(--red);
  font-weight: 900;
}

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

.stats-grid div {
  min-height: 70px;
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(247, 243, 235, 0.88);
  border: 1px solid rgba(29, 35, 40, 0.08);
}

.stats-grid dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.stats-grid dd {
  margin-top: 5px;
  font-size: 1.3rem;
  font-weight: 900;
}

.mini-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.daily-history {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.history-day {
  min-height: 54px;
  border: 1px solid rgba(29, 35, 40, 0.1);
  border-radius: var(--radius);
  background: rgba(247, 243, 235, 0.88);
  color: var(--ink);
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 6px 3px;
  font: inherit;
  text-align: center;
}

.history-day strong,
.history-day span {
  display: block;
  line-height: 1;
}

.history-day strong {
  font-size: 0.75rem;
}

.history-day span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.history-day.is-complete {
  background: var(--teal-soft);
  border-color: rgba(21, 122, 114, 0.28);
}

.history-day.is-today {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button.history-day.is-archive {
  cursor: pointer;
}

button.history-day.is-archive:hover {
  transform: translateY(-1px);
  border-color: rgba(21, 122, 114, 0.32);
}

.hint-panel {
  background: var(--gold-soft);
}

.hint-panel p {
  margin-top: 8px;
  line-height: 1.65;
}

.found-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: 360px;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.found-list li,
.empty-found {
  border: 1px solid rgba(29, 35, 40, 0.1);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.9);
  padding: 10px 12px;
}

.found-list strong {
  display: block;
  font-size: 1.05rem;
}

.found-list span,
.empty-found {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.store-dialog {
  width: min(480px, calc(100vw - 28px));
  border: 1px solid rgba(29, 35, 40, 0.14);
  border-radius: var(--radius);
  padding: 0;
  background: var(--paper-strong);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.store-dialog::backdrop,
.info-dialog::backdrop {
  background: rgba(29, 35, 40, 0.38);
}

.store-dialog form,
.info-dialog form {
  padding: 16px;
}

.icon-button {
  width: 38px;
  min-height: 38px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
}

.store-items {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.store-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  cursor: pointer;
}

.store-item strong,
.store-item small {
  display: block;
}

.store-item small {
  margin-top: 4px;
  color: var(--muted);
}

.store-item b {
  color: var(--teal);
  white-space: nowrap;
}

.store-item.is-owned {
  background: var(--teal-soft);
  border-color: rgba(21, 122, 114, 0.28);
}

.dialog-note {
  margin-top: 14px;
}

.info-dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid rgba(29, 35, 40, 0.14);
  border-radius: var(--radius);
  padding: 0;
  background: var(--paper-strong);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.tutorial-list {
  list-style: none;
  margin: 16px 0;
  padding: 0;
  display: grid;
  gap: 10px;
  counter-reset: tutorial;
}

.tutorial-list li {
  position: relative;
  min-height: 76px;
  border: 1px solid rgba(29, 35, 40, 0.1);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 12px 12px 12px 52px;
  counter-increment: tutorial;
}

.tutorial-list li::before {
  content: counter(tutorial);
  position: absolute;
  left: 12px;
  top: 12px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper-strong);
  display: grid;
  place-items: center;
  font-weight: 900;
}

.tutorial-list strong,
.tutorial-list span {
  display: block;
}

.tutorial-list strong {
  margin-bottom: 4px;
}

.tutorial-list span {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.full-button {
  width: 100%;
}

.result-rank {
  width: 104px;
  height: 104px;
  margin: 18px auto 10px;
  border: 5px solid var(--red);
  border-radius: 50%;
  color: var(--red);
  display: grid;
  place-items: center;
  font-size: 3.2rem;
  font-weight: 900;
  line-height: 1;
}

.result-summary {
  text-align: center;
  font-weight: 900;
}

.result-stats {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.result-stats div {
  border: 1px solid rgba(29, 35, 40, 0.1);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 10px 12px;
}

.result-stats dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.result-stats dd {
  margin-top: 4px;
  font-size: 1.2rem;
  font-weight: 900;
}

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

.reward-summary {
  margin-top: 16px;
  border: 1px solid rgba(21, 122, 114, 0.18);
  border-radius: var(--radius);
  background: var(--teal-soft);
  padding: 14px;
  display: grid;
  gap: 6px;
}

.reward-summary strong,
.reward-summary span {
  display: block;
}

.reward-summary strong {
  color: var(--teal);
  font-size: 1.05rem;
}

.reward-summary span {
  color: var(--ink);
  line-height: 1.55;
}

.tile.is-hint {
  outline: 3px solid var(--red);
  outline-offset: -5px;
}

.analytics-dialog {
  width: min(560px, calc(100vw - 28px));
}

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

.analytics-grid div {
  border: 1px solid rgba(29, 35, 40, 0.1);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 10px 12px;
}

.analytics-grid dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.analytics-grid dd {
  margin-top: 4px;
  font-size: 1.35rem;
  font-weight: 900;
}

.funnel-panel {
  margin-top: 14px;
  border: 1px solid rgba(29, 35, 40, 0.1);
  border-radius: var(--radius);
  background: rgba(247, 243, 235, 0.8);
  padding: 12px;
}

.funnel-panel h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.placement-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
}

.placement-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.placement-list strong {
  color: var(--ink);
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 20px, 680px);
    padding-top: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .controls {
    width: 100%;
  }

  .mode-button {
    flex: 1;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .round-header {
    align-items: flex-start;
  }

  .score-box {
    min-width: 78px;
  }

  .word-tray {
    align-items: flex-start;
    flex-direction: column;
  }

  .word-status {
    text-align: left;
  }

  .analytics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .board-zone,
  .status-panel,
  .history-panel,
  .hint-panel,
  .found-panel {
    padding: 12px;
  }

  .board {
    gap: 7px;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .daily-history {
    gap: 5px;
  }

  .history-day {
    min-height: 48px;
  }

  .result-actions {
    grid-template-columns: 1fr;
  }

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