:root {
  --ink: #17211d;
  --muted: #5b6d64;
  --paper: #f4f6f2;
  --surface: #ffffff;
  --header: #13221d;
  --header-ink: #f6fbf8;
  --header-muted: #b7d6c9;
  --green: #0a7d55;
  --mint: #4de1a4;
  --mint-soft: #dce8e2;
  --line: #aab8b1;
  --line-strong: #6c8a7c;
  --stage: #12372c;
  --stage-deep: #0c2b22;
  --cream: #fff8e7;
  --brass: #c59736;
  --brass-light: #f1d88b;
  --steel: #9cacaa;
  --wood: #8a5e37;
  --danger: #b73535;
  --flash-good: #fff8e7;
  --flash-warn: #ffe0a3;
  --flash-danger: #ffd4d4;
  font-family: "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(#edf2ee 1px, transparent 1px), var(--paper);
  background-size: 100% 32px;
  font-family: "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.6;
}
a { color: inherit; }
button, textarea { font: inherit; }
button { touch-action: manipulation; }

.site-header {
  min-height: 48px;
  padding: 0 max(16px, calc((100% - 1100px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: var(--header-ink);
  background: var(--header);
}
.site-header .brand {
  color: var(--header-ink);
  font-size: 16px;
  font-weight: 800;
  text-decoration: none;
}
.site-header p {
  margin: 0;
  color: var(--header-muted);
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 24px;
}
.mode-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  margin-bottom: 10px;
}
.eyebrow {
  margin: 0 0 2px;
  color: #3f6253;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
h1, h2, p { overflow-wrap: anywhere; }
h1 {
  margin: 0;
  color: #183126;
  font-size: 38px;
  line-height: 1.22;
  letter-spacing: 0px;
}
h1 small {
  display: block;
  margin: 0;
  color: #527063;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .01em;
}
.lead {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.start-controls {
  min-width: 310px;
  text-align: right;
}
.start-controls p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.primary-button, .secondary-button {
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 900;
  cursor: pointer;
}
.primary-button {
  min-width: 310px;
  padding: 9px 22px;
  color: #fff;
  background: var(--green);
  box-shadow: 0 2px 0 #07563b;
}
.secondary-button {
  padding: 6px 12px;
  color: #183126;
  background: #edf2ee;
  border-color: var(--line);
}
.primary-button:hover { background: #086e4b; }
.primary-button:focus-visible, .secondary-button:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid #edb83f;
  outline-offset: 2px;
}
.primary-button:disabled, .secondary-button:disabled { cursor: wait; opacity: .65; }

.game-shell {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #c8d1cc;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(18, 55, 44, .16);
  overflow: hidden;
}
.status-panel {
  min-height: 74px;
  padding: 9px 14px 8px;
  display: grid;
  grid-template-columns: minmax(225px, 1fr) minmax(480px, 1.65fr);
  gap: 14px;
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid #bdcbc4;
}
.status-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.status-head > div { min-width: 0; }
#status-code {
  display: block;
  color: #3f6253;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
}
#status-message {
  display: block;
  min-height: 24px;
  color: #183126;
  font-size: 15px;
  line-height: 1.45;
}
.status-metrics {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(70px, 1fr));
  border: 1px solid #bdcbc4;
  border-radius: 5px;
  overflow: hidden;
}
.status-metrics > div {
  min-width: 0;
  padding: 5px 6px 4px;
  text-align: center;
  background: #f1f5f2;
  border-left: 1px solid #bdcbc4;
}
.status-metrics > div:first-child { border-left: 0; }
.status-metrics dt {
  color: #5b6d64;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
}
.status-metrics dd {
  margin: -1px 0 0;
  color: #193c2e;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
}

.stage-wrap { padding: 8px 12px 0; background: #fff; }
.domino-stage {
  position: relative;
  height: 310px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 54%, rgba(77,225,164,.13), transparent 27%),
    linear-gradient(180deg, #164536, var(--stage-deep));
  border: 1px solid #577d6e;
  border-radius: 6px;
  isolation: isolate;
}
.domino-field {
  position: absolute;
  inset: 43px 8px 8px;
  overflow: hidden;
  border: 1px solid rgba(188,222,207,.35);
  border-radius: 4px;
}
.board-grid {
  position: absolute;
  inset: 0;
  opacity: .32;
  background:
    linear-gradient(90deg, transparent 49.7%, rgba(188,222,207,.22) 50%, transparent 50.3%),
    linear-gradient(transparent 49.7%, rgba(188,222,207,.14) 50%, transparent 50.3%);
  background-size: 72px 72px;
}
.domino-readout {
  position: absolute;
  z-index: 8;
  top: 8px;
  min-width: 96px;
  height: 28px;
  padding: 3px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  color: #f9f4dd;
  background: rgba(5,31,23,.86);
  border: 1px solid #6c9686;
  border-radius: 4px;
}
.left-readout { left: 8px; }
.right-readout { right: 8px; }
.domino-readout span { color: #b9d6ca; font-size: 10px; font-weight: 800; letter-spacing: .06em; }
.domino-readout strong { font-size: 15px; line-height: 1; }
.right-readout[data-level="warn"] { color: #2d2412; background: #ffe0a3; border-color: #ffe0a3; }
.right-readout[data-level="danger"] { color: #441414; background: #ffd4d4; border-color: #ffb3b3; }

.effects-canvas, .domino-scene, .card-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.effects-canvas { z-index: 3; pointer-events: none; }
.domino-scene { z-index: 1; pointer-events: none; }
.card-layer { z-index: 5; pointer-events: none; }
.core-zone {
  position: absolute;
  left: 50%;
  top: 52%;
  translate: -50% -50%;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #173b2f;
  background: radial-gradient(circle, #fff7d9 0 28%, #d6b45c 30% 48%, #193e32 50% 58%, #b9e3d1 60% 69%, rgba(21,60,47,.45) 71%);
  border: 2px solid #f1d77f;
  box-shadow: 0 0 0 5px rgba(77,225,164,.12), 0 7px 18px rgba(0,0,0,.28);
  text-align: center;
}
.core-zone span { position: relative; z-index: 2; font-size: 10px; font-weight: 900; letter-spacing: .08em; }
.core-zone i { position: absolute; inset: 11px; border: 1px dashed rgba(23,59,47,.6); border-radius: 50%; }
.route-key { position: absolute; right: 6px; bottom: 4px; display: flex; align-items: center; gap: 4px; color: #b9d6ca; font-size: 9px; font-weight: 800; }
.route-key strong { color: #fff2bc; }

.word-card {
  position: absolute;
  width: 82px;
  height: 40px;
  translate: -50% -50%;
  display: grid;
  place-items: center;
  color: #18261f;
  background: var(--cream);
  border: 2px solid #d7bd6a;
  border-radius: 3px;
  box-shadow: 0 4px 0 #7e6730, 0 7px 13px rgba(0,0,0,.28), inset 7px 0 0 rgba(197,151,54,.18);
  font-size: 19px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  will-change: left, top;
}
.word-card::before,
.word-card::after {
  content: "";
  position: absolute;
  left: 5px;
  width: 4px;
  height: 4px;
  border: 1px solid rgba(91,69,27,.55);
  border-radius: 50%;
}
.word-card::before { top: 5px; }
.word-card::after { bottom: 5px; }
.word-card[data-route-tone="mint"] { background: #e6f3ed; border-color: #91cbb2; box-shadow: 0 4px 0 #426f5d, 0 7px 13px rgba(0,0,0,.28), inset 7px 0 0 rgba(77,225,164,.14); }
.word-card.is-danger {
  color: #3f1212;
  background: #ffd9cf;
  border-color: #da655c;
  box-shadow: 0 4px 0 #8a2c28, 0 0 0 3px rgba(218,101,92,.2);
}
.word-card.is-broken { animation: card-broken .36s ease-out both; }
@keyframes card-broken { 45% { scale: 1.08; background: #d9f7e9; } 100% { scale: .7; opacity: 0; } }

.stage-flash {
  position: absolute;
  z-index: 12;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  min-width: 200px;
  padding: 4px 14px;
  color: var(--flash-good);
  background: rgba(6,38,28,.84);
  border-radius: 4px;
  text-align: center;
  font-size: 28px;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: .04em;
  opacity: 0;
  pointer-events: none;
}
.stage-flash.is-visible { animation: stage-flash .7s ease-out both; }
.stage-flash[data-tone="warn"] { color: var(--flash-warn); }
.stage-flash[data-tone="danger"] { color: var(--flash-danger); }
@keyframes stage-flash { 0% { opacity: 0; scale: .94; } 18%,70% { opacity: 1; scale: 1; } 100% { opacity: 0; scale: 1.02; } }

.input-panel {
  padding: 8px 14px 10px;
  background: #fff;
  border-top: 1px solid #bdcbc4;
}
.input-panel label {
  display: block;
  margin-bottom: 3px;
  color: #29493c;
  font-size: 12px;
  font-weight: 800;
}
textarea {
  display: block;
  width: 100%;
  height: 50px;
  min-height: 50px;
  max-height: 50px;
  padding: 7px 10px;
  resize: none;
  overflow: hidden;
  color: #13241d;
  background: #fff;
  border: 2px solid #8fb8a7;
  border-radius: 6px;
  font-size: 20px;
  font-weight: 700;
  line-height: 24px;
  caret-color: #087451;
}
textarea:disabled { color: #5b6d64; background: #edf2ee; cursor: not-allowed; }
.input-feedback {
  margin-top: 3px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: #5b6d64;
  font-size: 11px;
  line-height: 1.35;
}
.input-feedback p { margin: 0; }
.mode-safety-note { text-align: right; }

.result-panel, .how-to, .related-modes {
  margin-top: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid #c8d1cc;
  border-radius: 7px;
}
.result-panel h2, .how-to h2, .related-modes h2 { margin: 0 0 8px; color: #17382b; font-size: 22px; }
.result-grid {
  margin: 12px 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid #bdcbc4;
  border-radius: 5px;
  overflow: hidden;
}
.result-grid > div { padding: 7px; text-align: center; border-left: 1px solid #bdcbc4; }
.result-grid > div:first-child { border-left: 0; }
.result-grid dt { color: var(--muted); font-size: 11px; font-weight: 800; }
.result-grid dd { margin: 0; color: #193c2e; font-size: 18px; font-weight: 800; }
.result-history, #result-summary { margin: 5px 0; }
.how-to p { margin: 7px 0 0; color: #40554b; }
.related-modes { display: grid; grid-template-columns: 180px 1fr auto; gap: 16px; align-items: center; }
.related-modes h2 { margin-bottom: 0; }
.related-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.related-links a, .mode-list-link {
  display: block;
  padding: 8px 10px;
  color: #17382b;
  background: #f1f5f2;
  border: 1px solid #bdcbc4;
  border-radius: 5px;
  text-decoration: none;
}
.related-links small { display: block; color: var(--muted); font-size: 11px; }
.mode-list-link { white-space: nowrap; text-align: center; font-weight: 800; }
.site-footer {
  margin-top: 30px;
  padding: 22px 28px;
  color: var(--ink);
  background: #e6eee9;
}
.site-footer nav { max-width: 1100px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 12px 24px; }
.site-footer a { color: var(--ink); font-size: 13px; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
[hidden] { display: none !important; }

@media (max-width: 1099px) {
  .app-shell { width: min(100% - 20px, 1020px); padding-top: 8px; }
  .mode-intro { margin-bottom: 7px; }
  h1 { font-size: 33px; }
  .lead { font-size: 13px; }
  .status-panel { min-height: 68px; padding: 7px 10px; grid-template-columns: minmax(210px, .85fr) minmax(440px, 1.5fr); }
  .domino-stage { height: 296px; }
  .stage-wrap { padding: 6px 8px 0; }
  .input-panel { padding: 6px 10px 8px; }
  textarea { height: 46px; min-height: 46px; max-height: 46px; }
}

@media (max-width: 760px) {
  .site-header { min-height: 48px; padding: 0 14px; }
  .site-header .brand { font-size: 16px; }
  .site-header p { font-size: 11px; }
  .app-shell { width: calc(100% - 12px); padding-top: 6px; }
  .mode-intro { grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
  .eyebrow, .lead, .start-controls p { display: none; }
  h1 { font-size: 30px; line-height: 1.05; }
  h1 small { display: block; margin: 1px 0 0; font-size: 12px; }
  .start-controls { min-width: 105px; }
  .primary-button { min-width: 104px; padding: 8px 10px; }
  .game-shell { border-radius: 6px; }
  .status-panel { min-height: 87px; display: block; padding: 6px 7px; }
  .status-head { min-height: 31px; }
  #status-message { min-height: 18px; font-size: 13px; line-height: 1.25; }
  #status-code { font-size: 9px; }
  .secondary-button { padding: 4px 8px; font-size: 12px; }
  .status-metrics { margin-top: 4px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .status-metrics > div { padding: 3px 1px 2px; }
  .status-metrics dt { font-size: 8px; letter-spacing: 0; }
  .status-metrics dd { font-size: 13px; }
  .stage-wrap { padding: 5px 5px 0; }
  .domino-stage { height: 278px; }
  .domino-field { inset: 39px 5px 5px; }
  .domino-readout { top: 6px; min-width: 86px; height: 27px; padding: 2px 7px; }
  .left-readout { left: 6px; }
  .right-readout { right: 6px; }
  .domino-readout span { font-size: 8px; }
  .domino-readout strong { font-size: 13px; }
  .core-zone { width: 54px; height: 54px; }
  .core-zone span { font-size: 8px; }
  .word-card { width: 70px; height: 34px; font-size: 16px; border-width: 1px; box-shadow: 0 3px 0 #7e6730, 0 5px 9px rgba(0,0,0,.26); }
  .word-card[data-route-tone="mint"] { box-shadow: 0 3px 0 #426f5d, 0 5px 9px rgba(0,0,0,.26), inset 6px 0 0 rgba(77,225,164,.14); }
  .stage-flash { min-width: 150px; padding: 3px 9px; font-size: 21px; }
  .input-panel { padding: 5px 7px 6px; }
  .input-panel label { margin-bottom: 1px; font-size: 10px; }
  textarea { height: 42px; min-height: 42px; max-height: 42px; padding: 5px 8px; font-size: 17px; }
  .input-feedback { font-size: 9px; gap: 5px; }
  .mode-safety-note { max-width: 42%; }
  .result-panel, .how-to, .related-modes { margin-top: 10px; padding: 14px; }
  .result-grid { grid-template-columns: repeat(3, 1fr); }
  .result-grid > div { border-top: 1px solid #bdcbc4; }
  .result-grid > div:nth-child(-n+3) { border-top: 0; }
  .related-modes { display: block; }
  .related-links { margin-top: 8px; grid-template-columns: 1fr; }
  .mode-list-link { margin-top: 8px; }
  .site-footer { margin-top: 20px; padding: 18px 14px; }
}

@media (max-width: 410px) {
  .domino-stage { height: 272px; }
  .domino-field { inset: 38px 5px 5px; }
  .input-feedback { display: block; }
  .mode-safety-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .stage-flash.is-visible, .word-card.is-broken { animation-duration: .12s; }
}
