: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;
  --wood-light: #b98552;
  --metal: #91a69d;
  --ochre: #c59736;
  --danger: #b73535;
  --flash-surface: #0c2b22;
  --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, input { 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;
  justify-content: space-between;
  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:focus-visible, input: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;
  border-color: #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: 69px;
  display: grid;
  grid-template-columns: minmax(230px, 1.3fr) minmax(360px, 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(4, 1fr);
}
.status-metrics div {
  min-width: 0;
  padding: 9px 8px;
  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 15px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.stage-wrap { background: var(--stage-deep); }
.seesaw-stage {
  position: relative;
  height: 320px;
  min-height: 304px;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(180deg, rgba(255,255,255,.025), transparent 42%),
    var(--stage);
}
.seesaw-stage::after {
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 6%;
  height: 2px;
  background: rgba(255, 248, 231, .26);
  z-index: 0;
}
.load-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; }
.load-readout span {
  color: var(--header-muted);
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
}
.load-readout strong {
  color: var(--cream);
  font: 900 18px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.danger-meter {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 8;
  width: min(230px, 44%);
  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;
}
.danger-meter span { color: var(--header-muted); }
.danger-meter strong { color: var(--mint); letter-spacing: .04em; }
.danger-meter i {
  grid-column: 1 / -1;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(183, 214, 201, .22);
}
.danger-meter b {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--mint);
  transition: width .18s linear, background .18s;
}
.danger-meter[data-level="warning"] strong { color: #e1b75b; }
.danger-meter[data-level="warning"] b { background: var(--ochre); }
.danger-meter[data-level="danger"] strong { color: #ff9a9a; }
.danger-meter[data-level="danger"] b {
  background: var(--danger);
  animation: danger-pulse .7s ease-in-out infinite alternate;
}

.seesaw-rig { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.seesaw-beam {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 69%;
  height: 18px;
  transform-origin: 50% 50%;
  transition: transform .32s cubic-bezier(.22, .8, .36, 1);
  border: 2px solid #6f492c;
  border-radius: 999px;
  background: linear-gradient(var(--wood-light), var(--wood));
  box-shadow: 0 7px 12px rgba(0, 0, 0, .3);
}
.seesaw-beam::after {
  content: "";
  position: absolute;
  inset: 4px 7%;
  border-top: 2px solid rgba(255, 248, 231, .35);
}
.pan { position: absolute; width: 36%; height: 72px; top: -58px; }
.pan-left { left: -1%; }
.pan-right { right: -1%; }
.pan::before, .pan::after {
  content: "";
  position: absolute;
  top: 6px;
  width: 2px;
  height: 38px;
  background: var(--metal);
  transform-origin: top;
}
.pan::before { left: 9%; transform: rotate(15deg); }
.pan::after { right: 9%; transform: rotate(-15deg); }
.pan span {
  position: absolute;
  left: 2%;
  right: 2%;
  bottom: 0;
  height: 18px;
  border: 2px solid #b7c9c1;
  border-top: 0;
  border-radius: 0 0 50% 50%;
  background: rgba(255, 248, 231, .25);
}
.fulcrum {
  position: absolute;
  left: 50%;
  top: calc(69% + 14px);
  width: 92px;
  height: 90px;
  transform: translateX(-50%);
}
.fulcrum::before {
  content: "";
  position: absolute;
  left: 50%;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 42px solid transparent;
  border-right: 42px solid transparent;
  border-bottom: 82px solid #71887e;
}
.fulcrum span {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 12px;
  width: 21px;
  height: 21px;
  transform: translateX(-50%);
  border: 4px solid #c8d4cf;
  border-radius: 50%;
  background: #35594b;
}

.block-layer { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.word-block {
  --x: 16%;
  --y: 12%;
  --weight-color: #65b996;
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: clamp(56px, 8vw, 82px);
  min-height: 43px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  align-content: center;
  padding: 5px 4px 4px;
  border: 2px solid var(--weight-color);
  border-radius: 5px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: 0 5px 0 color-mix(in srgb, var(--weight-color), #4a3522 34%), 0 9px 13px rgba(0,0,0,.24);
  transition-property: top, left, transform, opacity;
  transition-timing-function: linear;
  will-change: top, left, transform;
}
.word-block[data-weight="2"] { --weight-color: var(--ochre); }
.word-block[data-weight="3"] { --weight-color: var(--wood); background: #f3e2bd; }
.word-block[data-status="falling"] { top: 7%; }
.word-block .word {
  font-size: clamp(12px, 1.4vw, 16px);
  font-weight: 1000;
  line-height: 1;
  white-space: nowrap;
}
.word-block .weight-mark {
  margin-top: 4px;
  color: #57452f;
  font-size: 8px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 1px;
}
.word-block.is-clearing {
  opacity: 0;
  transform: translate(-50%, -50%) scale(.7);
  transition-duration: 150ms !important;
}
.word-block.is-heavy { outline: 2px solid rgba(255, 248, 231, .38); outline-offset: 2px; }

.stage-guide {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: 8px;
  width: min(92%, 640px);
  margin: 0;
  transform: translateX(-50%);
  color: var(--header-muted);
  text-align: center;
  font-size: 10px;
}
.stage-flash {
  position: absolute;
  z-index: 10;
  left: 50%;
  top: 49%;
  min-width: 180px;
  transform: translate(-50%, -50%);
  text-align: center;
  padding: 9px 16px;
  border: 1px solid rgba(255, 248, 231, .52);
  border-radius: 6px;
  color: var(--flash-good);
  background: var(--flash-surface);
  font-size: clamp(17px, 3vw, 28px);
  font-weight: 1000;
  line-height: 1;
  text-shadow: 0 2px 5px rgba(0,0,0,.65);
  pointer-events: none;
  opacity: 0;
  transition: opacity .16s ease, transform .16s ease;
}
.stage-flash[data-tone="good"] { color: var(--flash-good); }
.stage-flash[data-tone="warn"] { color: var(--flash-warn); }
.stage-flash[data-tone="danger"] { color: var(--flash-danger); }
.stage-flash.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.input-panel {
  min-height: 88px;
  padding: 9px 14px 10px;
  display: grid;
  grid-template-columns: minmax(170px, .7fr) minmax(250px, 1.1fr) minmax(300px, 1.4fr);
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.input-panel label { font-size: 12px; font-weight: 900; }
#typing-input {
  width: 100%;
  height: 54px;
  min-height: 54px;
  border: 2px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface);
  font-size: 16.64px;
  font-weight: 800;
  line-height: 1.35;
  ime-mode: active;
}
#typing-input:disabled {
  cursor: not-allowed;
  color: #748079;
  background: #e8ece9;
}
.input-feedback { min-width: 0; }
.input-feedback p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
}
.input-feedback .mode-safety-note { margin-top: 2px; color: #748079; }

.result-panel {
  margin: 30px 0 0;
  padding: 20px 0 0;
  border-top: 1px solid var(--line);
}
.how-to, .related-modes {
  margin: 30px 0 0;
  padding: 20px 0 0;
  border-top: 1px solid var(--line);
  background: transparent;
}
.result-panel h2, .how-to h2, .related-modes h2 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 20px;
}
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}
.result-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.result-grid dt { color: var(--muted); font-size: 10px; }
.result-grid dd {
  margin: 4px 0 0;
  font: 900 18px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.how-to p {
  margin: 6px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}
.related-modes { display: block; }
.related-links {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.related-links a {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  text-decoration: none;
  background: var(--surface);
}
.related-links strong, .related-links small { display: block; }
.related-links strong { font-size: 11px; }
.related-links small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  line-height: 1.2;
}
.mode-list-link {
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.site-footer {
  min-height: 69.59px;
  padding: 22px 18px;
  color: var(--mint-soft);
  background: var(--header);
}
.site-footer nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 20px;
}
.site-footer a {
  color: var(--mint-soft);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.6;
}
.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;
}

@keyframes danger-pulse { to { filter: brightness(1.35); } }
@media (max-width: 760px) {
  .app-shell { width: auto; margin-right: 14px; margin-left: 14px; padding-top: 12px; }
  .mode-intro {
    min-height: 0;
    padding: 4px 0 14px;
    grid-template-columns: 1fr;
    gap: 14px;
  }
  h1 { font-size: clamp(24px, 7vw, 30px); }
  .lead { font-size: 12px; }
  .start-controls { width: 100%; gap: 7px; }
  .start-controls p { display: none; }
  .primary-button { width: 100%; min-height: 46px; }
  .secondary-button { min-height: 32px; padding: 4px 8px; font-size: 11.2px; }
  .status-panel { min-height: 96px; display: block; }
  .status-head {
    height: 47px;
    padding: 7px 10px 7px 14px;
    border-right: 0;
    border-bottom: 1px solid #406357;
  }
  #status-message { max-width: 250px; font-size: 11px; }
  .status-metrics { height: 49px; }
  .status-metrics div { padding: 6px 3px; }
  .status-metrics dd { font-size: 13px; }
  .seesaw-stage { height: 310px; min-height: 310px; }
  .load-readout { top: 7px; padding: 4px 6px; }
  .left-readout { left: 7px; }
  .right-readout { right: 7px; }
  .load-readout span { font-size: 6px; }
  .load-readout strong { font-size: 15px; }
  .danger-meter { top: 8px; width: 37%; font-size: 7px; }
  .seesaw-beam { left: 5%; right: 5%; top: 70%; }
  .pan { width: 39%; }
  .fulcrum { top: calc(70% + 14px); }
  .word-block { width: clamp(53px, 16vw, 64px); min-height: 39px; padding: 4px 2px; }
  .word-block .word { font-size: clamp(11px, 3.4vw, 14px); }
  .stage-guide { bottom: 6px; font-size: 8px; }
  .input-panel {
    min-height: 91px;
    padding: 7px 9px;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    gap: 5px 8px;
  }
  .input-panel label { font-size: 9px; }
  #typing-input {
    height: 46px;
    min-height: 46px;
    padding: 7px 9px;
    font-size: 15.36px;
    grid-row: 1 / 3;
    grid-column: 2;
  }
  .input-feedback { grid-column: 1; align-self: start; }
  .input-feedback p { font-size: 7px; line-height: 1.35; }
  .mode-safety-note { display: none; }
  .result-panel, .how-to, .related-modes { margin-top: 30px; padding-top: 20px; }
  .related-modes { display: block; }
  .related-links { margin: 10px 0; }
}

@media (max-width: 430px) {
  .site-header { height: 44px; min-height: 44px; padding: 7px 14px; }
  .site-header p { display: none; }
  .brand { font-size: 16px; }
  .mode-intro {
    min-height: 0;
    padding: 4px 0 14px;
    align-content: center;
    gap: 14px;
  }
  .start-controls { width: 100%; }
  .seesaw-stage { height: 310px; }
  .word-block { width: 54px; }
  .related-links { grid-template-columns: 1fr; }
  .site-footer { min-height: 105.19px; padding: 22px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
