: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;
  --metal: #b9c5bf;
  --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; }
.brand { color: var(--header-ink); font-size: 16px; font-weight: 800; 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: 38px; 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); }
.pinball-stage {
  position: relative;
  height: 316px;
  min-height: 300px;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(180deg, rgba(255,255,255,.035), transparent 48%), var(--stage);
}
.table-readout { position: absolute; top: 9px; 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,.92); }
.left-readout { left: 12px; }
.right-readout { right: 12px; }
.table-readout span { color: var(--header-muted); font-size: 8px; font-weight: 700; line-height: 1; }
.table-readout strong { color: var(--cream); font: 900 16px/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.right-readout[data-level="danger"] { border-color: #e8a2a2; }
.right-readout[data-level="danger"] strong { color: var(--flash-danger); }

.pinball-field {
  position: absolute;
  inset: 42px 8px 35px;
  z-index: 1;
  overflow: hidden;
  border: 1px solid rgba(183,214,201,.38);
  border-bottom-color: rgba(255,248,231,.62);
  border-radius: 48% 48% 10px 10px / 22px 22px 10px 10px;
  background:
    linear-gradient(90deg, transparent 49.7%, rgba(77,225,164,.14) 50%, transparent 50.3%),
    linear-gradient(180deg, rgba(255,248,231,.055), transparent 28%),
    var(--stage-deep);
  box-shadow: inset 0 0 0 5px rgba(108,138,124,.12);
}
.table-lanes, .ball-layer { position: absolute; inset: 0; }
.table-lanes i { position: absolute; top: 16px; bottom: 40px; width: 1px; background: linear-gradient(transparent, rgba(183,214,201,.2), transparent); }
.table-lanes i:nth-child(1) { left: 24%; transform: rotate(7deg); }
.table-lanes i:nth-child(2) { left: 50%; }
.table-lanes i:nth-child(3) { right: 24%; transform: rotate(-7deg); }
.bumper { position: absolute; z-index: 1; width: 42px; height: 42px; border: 3px solid var(--ochre); border-radius: 50%; background: var(--cream); box-shadow: inset 0 0 0 6px #dce8e2, 0 3px 0 rgba(5,34,25,.45); }
.bumper span { position: absolute; inset: 11px; border-radius: 50%; background: var(--wood); }
.bumper-a { left: 24%; top: 28%; }
.bumper-b { left: 50%; top: 47%; transform: translate(-50%, -50%); }
.bumper-c { right: 24%; top: 28%; }
.bumper.is-active { border-color: var(--mint); box-shadow: 0 0 0 5px rgba(77,225,164,.25), 0 3px 0 rgba(5,34,25,.45); }
.flipper { position: absolute; bottom: 22px; z-index: 2; width: 92px; height: 13px; border: 2px solid var(--cream); border-radius: 8px; background: var(--wood); box-shadow: 0 3px 0 rgba(5,34,25,.5); transform-origin: 90% 50%; }
.flipper-left { left: calc(50% - 103px); transform: rotate(16deg); }
.flipper-right { right: calc(50% - 103px); transform: rotate(-16deg); transform-origin: 10% 50%; }
.pinball-stage.flipper-hit .flipper-left { animation: flip-left .22s ease-out; }
.pinball-stage.flipper-hit .flipper-right { animation: flip-right .22s ease-out; }
.drain-slot { position: absolute; left: 50%; bottom: 3px; z-index: 1; width: 112px; height: 18px; overflow: hidden; transform: translateX(-50%); border-top: 3px solid var(--ochre); border-radius: 50% 50% 0 0; background: #071b15; color: var(--header-muted); font-size: 0; line-height: 1; text-align: center; }
.drain-slot span { display: block; font: 900 8px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .12em; }

.pinball-ball {
  position: absolute;
  z-index: 4;
  width: 72px;
  height: 42px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  padding: 3px 7px;
  border: 2px solid #a8d7c2;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff 0 8%, var(--cream) 9% 60%, #ead7ac 100%);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(5,34,25,.4);
  will-change: left, top;
}
.pinball-ball .ball-word { position: relative; z-index: 1; white-space: nowrap; font-size: 13px; font-weight: 900; line-height: 1; }
.pinball-ball[data-state="danger"] { border-color: #ef9c9c; background: radial-gradient(circle at 35% 28%, #fff 0 8%, #fff3ec 9% 60%, #efc0aa 100%); box-shadow: 0 0 0 3px rgba(183,53,53,.24), 0 4px 0 rgba(5,34,25,.4); }
.pinball-ball[data-state="hit"] .ball-word { animation: ball-return .24s ease-out; }

.stage-guide { position: absolute; left: 50%; bottom: 9px; 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: 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; }

.input-panel { padding: 14px 18px 15px; 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: 50px; resize: none; overflow: hidden; border: 2px solid var(--line-strong); border-radius: 6px; padding: 9px 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: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.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: 780px; 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; }

@keyframes flash-in { to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes flip-left { 45% { transform: rotate(-20deg); } }
@keyframes flip-right { 45% { transform: rotate(20deg); } }
@keyframes ball-return { 50% { transform: translateY(-8px) scale(1.08); } 100% { transform: translateY(-18px) scale(.9); opacity: 0; } }

@media (max-width: 1266px) { h1 { font-size: 33px; } }
@media (max-width: 1099px) { h1 { font-size: 30px; } }
@media (max-width: 999px) { h1 { font-size: 28px; } }

@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; }
  .pinball-stage { height: 306px; }
  .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: 30px; }
  .stage-flash { font-size: 20px; }
  .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; }
  .pinball-stage { height: 300px; min-height: 300px; }
  .pinball-field { inset-inline: 5px; }
  .pinball-ball { width: 66px; height: 39px; padding-inline: 5px; }
  .pinball-ball .ball-word { font-size: 12px; }
  .bumper { width: 38px; height: 38px; }
  .flipper { width: 74px; }
  .flipper-left { left: calc(50% - 83px); }
  .flipper-right { right: calc(50% - 83px); }
  .table-readout { padding: 4px 7px; }
  .stage-guide { font-size: 10px; }
  .input-panel { padding: 12px 12px 13px; }
  .input-feedback { display: grid; gap: 0; }
  .input-feedback p { margin-top: 5px; }
  .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 (max-width: 374px) { h1 { font-size: 27px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
