: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;
  --wood: #8a5e37;
  --ochre: #c59736;
  --danger: #b73535;
  --danger-soft: #ffd4d4;
  --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; }

.site-header {
  height: 48px;
  min-height: 48px;
  padding: 9px max(18px, calc((100% - 1100px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 4px solid var(--mint);
  background: var(--header);
  color: var(--header-ink);
}
.site-header p { margin: 0; color: var(--header-muted); font-size: 12.48px; font-weight: 700; line-height: 1.6; }
.brand { color: var(--header-ink); font-size: 16px; font-weight: 800; line-height: 1.6; text-decoration: none; }
.app-shell { width: auto; margin: 0 max(18px, calc((100% - 1100px) / 2)); padding: 18px 0 52px; }
@media (min-width: 1100px) { .app-shell { width: min(1100px, calc(100% - 36px)); margin: 0 auto; } }

.mode-intro {
  min-height: 138px;
  padding: 4px 0 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}
.eyebrow { margin: 0 0 3px; color: var(--green); font-size: 12px; font-weight: 800; line-height: 1.5; }
h1 { margin: 0; color: var(--ink); font-size: clamp(28px, 3vw, 40px); font-weight: 900; line-height: 1.22; }
h1 small { display: block; margin-top: 2px; color: var(--muted); font-size: 16px; font-weight: 700; line-height: 1.5; }
.lead { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.start-controls { width: 310px; display: grid; gap: 8px; }
.start-controls p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

button {
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  padding: 9px 18px;
  color: #fff;
  background: var(--green);
  font-size: 16px;
  font-weight: 900;
  box-shadow: 0 4px 0 #07573d;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { filter: brightness(1.06); }
button:disabled { cursor: wait; opacity: .76; }
button:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; }
.primary-button { display: block; width: 100%; }
.secondary-button { min-height: 38px; padding: 7px 13px; color: var(--header); background: var(--mint-soft); border: 1px solid #91aa9e; font-size: 16px; font-weight: 900; box-shadow: none; }

.game-shell { overflow: hidden; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.status-panel {
  min-height: 70px;
  display: grid;
  grid-template-columns: minmax(230px, 1.2fr) minmax(420px, 1fr);
  align-items: stretch;
  color: var(--header-ink);
  background: var(--header);
  border-bottom: 1px solid #406357;
  box-shadow: inset 5px 0 0 var(--mint);
}
.status-head { min-width: 0; padding: 10px 15px 10px 19px; display: flex; justify-content: space-between; align-items: center; gap: 10px; border-right: 1px solid #406357; }
.status-head > div { display: grid; min-width: 0; gap: 3px; }
#status-code { color: var(--mint); font: 900 10px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .08em; }
#status-message { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.status-metrics { margin: 0; display: grid; grid-template-columns: repeat(5, 1fr); }
.status-metrics div { min-width: 0; padding: 9px 5px; display: grid; align-content: center; justify-items: center; border-right: 1px solid #406357; }
.status-metrics div:last-child { border-right: 0; }
.status-metrics dt { color: var(--header-muted); font-size: 9px; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.status-metrics dd { margin: 3px 0 0; color: var(--header-ink); font: 900 14px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }

.stage-wrap { background: var(--stage-deep); }
.whirlpool-stage {
  position: relative;
  height: 336px;
  min-height: 310px;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(180deg, rgba(255,255,255,.025), transparent 44%), var(--stage);
}
.whirlpool-stage::after { content: ""; position: absolute; left: 4%; right: 4%; bottom: 6%; height: 2px; background: rgba(255,248,231,.26); z-index: 0; }
.current-readout { position: absolute; top: 10px; z-index: 8; display: flex; align-items: baseline; gap: 7px; padding: 5px 9px; border: 1px solid rgba(183,214,201,.5); border-radius: 5px; background: rgba(12,43,34,.9); }
.left-readout { left: 12px; }
.right-readout { right: 12px; }
.current-readout span { color: var(--header-muted); font-size: 8px; font-weight: 700; line-height: 1; }
.current-readout strong { color: var(--cream); font: 900 16px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.core-meter { position: absolute; top: 10px; left: 50%; z-index: 8; width: min(230px, 42%); transform: translateX(-50%); display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; color: var(--header-muted); font: 800 9px/1.1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.core-meter > span { color: var(--header-muted); }
.core-meter strong { color: var(--mint); letter-spacing: .04em; }
.core-meter i { grid-column: 1 / -1; height: 5px; overflow: hidden; border-radius: 999px; background: rgba(183,214,201,.22); }
.core-meter b { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--mint); transition: width .18s linear, background .18s; }
.core-meter[data-level="warning"] strong { color: var(--ochre); }
.core-meter[data-level="warning"] b { background: var(--ochre); }
.core-meter[data-level="danger"] strong { color: #ff9a9a; }
.core-meter[data-level="danger"] b { background: var(--danger); animation: danger-pulse .7s ease-in-out infinite alternate; }

.whirlpool-field { position: absolute; inset: 48px 8px 38px; z-index: 1; overflow: hidden; }
.whirlpool-rings { position: absolute; left: 50%; top: 54%; width: min(96%, 980px); height: min(88%, 238px); transform: translate(-50%, -50%) rotate(-8deg); border: 1px solid rgba(255,248,231,.2); border-radius: 48% 52% 46% 54% / 52% 44% 56% 48%; }
.whirlpool-rings::before, .whirlpool-rings::after, .whirlpool-rings i { content: ""; position: absolute; border: 1px solid rgba(77,225,164,.28); border-radius: 50%; }
.whirlpool-rings::before { inset: 12% 9%; border-radius: 46% 54% 50% 50% / 48% 42% 58% 52%; }
.whirlpool-rings::after { inset: 25% 21%; border-radius: 52% 48% 44% 56% / 54% 46% 54% 46%; }
.whirlpool-rings i:nth-child(1) { inset: 42%; border-color: rgba(255,248,231,.35); }
.whirlpool-rings i:nth-child(2) { inset: 7% 22% 43% 38%; border-left-color: transparent; border-bottom-color: transparent; transform: rotate(26deg); }
.whirlpool-rings i:nth-child(3) { inset: 43% 33% 14% 8%; border-right-color: transparent; border-top-color: transparent; transform: rotate(28deg); }
.core { position: absolute; left: 50%; top: 54%; z-index: 2; width: 64px; height: 64px; transform: translate(-50%, -50%); display: grid; place-items: center; border: 2px solid var(--ochre); border-radius: 50%; background: var(--stage-deep); color: var(--cream); box-shadow: inset 0 0 0 7px rgba(197,151,54,.16); }
.core span { position: absolute; width: 22px; height: 22px; border: 2px solid var(--mint); border-radius: 50%; }
.core strong { position: relative; margin-top: 2px; font: 900 8px/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .04em; }
.word-layer { position: absolute; inset: 0; }
.word-card { position: absolute; z-index: 4; width: 46px; min-height: 32px; transform: translate(-50%, -50%); display: grid; align-items: center; padding: 3px; border: 2px solid #a8d7c2; border-radius: 7px; background: var(--cream); color: var(--ink); box-shadow: 0 4px 0 rgba(5,34,25,.35); transition: opacity .18s ease, transform .18s ease; }
.word-card .word { min-width: 0; overflow-wrap: anywhere; font-size: 11px; font-weight: 900; line-height: 1.2; text-align: center; }
.word-card[data-state="danger"] { border-color: #f1a5a5; background: #fff3ec; }
.word-card[data-state="impact"] { border-color: #f1a5a5; background: #fff3ec; box-shadow: 0 0 0 3px rgba(183,53,53,.25); }
.word-card[data-state="clearing"] { opacity: 0; transform: translate(-50%, -50%) scale(.88); }
.word-card[data-state="incoming"]::after { content: ""; position: absolute; right: 8px; bottom: 3px; width: 18px; height: 2px; background: var(--mint); opacity: .7; }
.stage-guide { position: absolute; left: 50%; bottom: 10px; z-index: 8; width: min(92%, 680px); transform: translateX(-50%); margin: 0; color: var(--header-muted); font-size: 11px; text-align: center; }
.stage-flash { position: absolute; left: 50%; top: 52%; z-index: 12; min-width: min(82%, 360px); transform: translate(-50%, -50%) scale(.96); padding: 11px 18px; border: 2px solid var(--mint); border-radius: 7px; background: rgba(12,43,34,.97); color: var(--flash-good); font-size: clamp(20px, 3.2vw, 30px); font-weight: 900; line-height: 1.2; text-align: center; opacity: 0; pointer-events: none; }
.stage-flash[data-tone="warn"] { border-color: var(--ochre); color: var(--flash-warn); }
.stage-flash[data-tone="danger"] { border-color: #e8a2a2; color: var(--flash-danger); }
.stage-flash.show { animation: flash-in .2s ease-out forwards; }
@keyframes flash-in { to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes danger-pulse { from { opacity: .7; } to { opacity: 1; } }

.input-panel { padding: 15px 18px 17px; border-top: 1px solid #406357; background: var(--surface); }
.input-panel label { display: block; margin-bottom: 5px; color: var(--ink); font-size: 13px; font-weight: 900; }
#typing-input { display: block; width: 100%; min-height: 54px; resize: none; overflow: hidden; border: 2px solid var(--line-strong); border-radius: 6px; padding: 11px 13px; color: var(--ink); background: #fff; font-size: 20px; font-weight: 800; line-height: 1.35; }
#typing-input:disabled { color: var(--muted); background: #edf2ee; cursor: not-allowed; }
.input-feedback { display: flex; justify-content: space-between; gap: 16px; }
.input-feedback p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.mode-safety-note { text-align: right; }

.result-panel { margin-top: 22px; padding: 22px 24px 24px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.result-panel h2, .how-to h2, .related-modes h2 { margin: 0; color: var(--ink); font-size: 24px; line-height: 1.3; }
.result-grid { margin: 18px 0; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-grid div { padding: 11px 12px; border-right: 1px solid var(--line); }
.result-grid div:last-child { border-right: 0; }
.result-grid dt { color: var(--muted); font-size: 11px; font-weight: 800; }
.result-grid dd { margin: 2px 0 0; color: var(--green); font: 900 18px/1.25 ui-monospace, SFMono-Regular, Consolas, monospace; }
#result-summary { margin: 0 0 17px; color: var(--muted); }
.how-to { padding: 28px 0 0; }
.how-to p:not(.eyebrow) { max-width: 760px; margin: 9px 0 0; color: var(--muted); font-size: 14px; }
.related-modes { margin-top: 30px; padding: 19px 0 0; display: grid; grid-template-columns: 220px 1fr auto; align-items: center; gap: 18px; border-top: 1px solid var(--line); }
.related-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.related-links a { display: grid; gap: 2px; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); text-decoration: none; }
.related-links a:hover { border-color: var(--green); }
.related-links strong { font-size: 13px; }
.related-links small { color: var(--muted); font-size: 11px; }
.mode-list-link { color: var(--green); font-size: 13px; font-weight: 800; white-space: nowrap; }
.site-footer { padding: 22px max(18px, calc((100% - 1100px) / 2)); border-top: 1px solid var(--line); background: #e6eee9; }
.site-footer nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px 24px; }
.site-footer a { color: var(--muted); font-size: 12px; text-decoration: none; }
.site-footer a:hover { color: var(--green); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .mode-intro { grid-template-columns: minmax(0, 1fr) 245px; gap: 16px; }
  .start-controls { width: auto; }
  .status-panel { grid-template-columns: 1fr; }
  .status-head { border-right: 0; border-bottom: 1px solid #406357; }
  .related-modes { grid-template-columns: 180px 1fr; }
  .mode-list-link { grid-column: 2; }
}
@media (max-width: 620px) {
  .site-header { padding-inline: 14px; }
  .app-shell { margin-inline: 14px; padding-top: 14px; }
  .mode-intro { min-height: 0; padding-bottom: 15px; grid-template-columns: 1fr; gap: 13px; }
  h1 { font-size: clamp(27px, 8vw, 34px); }
  .start-controls { width: 100%; }
  .status-head { padding: 9px 11px 9px 15px; }
  #status-message { font-size: 12px; }
  .status-metrics div { padding-inline: 2px; }
  .status-metrics dt { font-size: 8px; }
  .status-metrics dd { font-size: 12px; }
  .whirlpool-stage { height: 332px; min-height: 300px; }
  .whirlpool-field { inset-inline: 5px; }
  .whirlpool-rings { width: min(96%, 680px); height: min(88%, 238px); }
  .word-card { width: 46px; min-height: 32px; padding: 3px; }
  .word-card .word { font-size: 11px; }
  .current-readout { padding: 4px 7px; }
  .core-meter { width: 38%; }
  .stage-guide { font-size: 10px; }
  .input-panel { padding: 13px 12px 14px; }
  .input-feedback { display: grid; gap: 0; }
  .input-feedback p { margin-top: 6px; }
  .mode-safety-note { text-align: left; }
  .result-panel { padding: 18px 15px 20px; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
  .result-grid div:nth-child(2) { border-right: 0; }
  .result-grid div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .related-modes { grid-template-columns: 1fr; gap: 12px; }
  .related-links { grid-template-columns: 1fr; }
  .mode-list-link { grid-column: auto; }
  .site-footer { padding-inline: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
