:root {
  color-scheme: light;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
  color: #34283b;
  background: #f1e3cf;
  --ink: #34283b;
  --deep: #3b293f;
  --cream: #fff9ec;
  --paper: #fffdf4;
  --desk: #e9c792;
  --coral: #ec776d;
  --mint: #64b994;
  --violet: #8874ad;
  --gold: #e7b94d;
  --line: rgba(52, 40, 59, 0.22);
}

* { box-sizing: border-box; }
html { min-width: 320px; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 12%, rgba(255,255,255,.8), transparent 27rem),
    linear-gradient(135deg, rgba(136,116,173,.08) 25%, transparent 25%) 0 0 / 34px 34px,
    #f1e3cf;
}

button, a { font: inherit; }
button { color: inherit; }

.page-shell {
  width: min(1180px, calc(100% - 40px));
  margin-inline: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
  color: var(--deep);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .11em;
}

.workspace-link { color: inherit; text-decoration: none; }
.workspace-link:hover { color: var(--coral); }
.topbar-actions { display: flex; align-items: center; gap: 22px; }

.text-button {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-bottom: 2px solid currentColor;
  background: transparent;
  cursor: pointer;
  font-weight: 900;
  letter-spacing: .06em;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(380px, 560px);
  gap: clamp(36px, 7vw, 96px);
  align-items: center;
  padding-block: 46px 56px;
}

.game-copy { align-self: center; }

.eyebrow {
  margin: 0 0 16px;
  color: #8a5061;
  font: 900 .78rem/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: .15em;
}

h1 {
  margin: 0;
  color: var(--deep);
  font-size: clamp(4rem, 8vw, 7.4rem);
  font-weight: 950;
  line-height: .88;
  letter-spacing: -.08em;
}

h1 em {
  color: var(--coral);
  font-style: normal;
  text-shadow: 4px 4px 0 rgba(255,255,255,.8);
}

.lead {
  margin: 30px 0 26px;
  color: #59495d;
  font-size: clamp(.96rem, 1.7vw, 1.08rem);
  font-weight: 700;
  line-height: 1.9;
}

.rhythm-card {
  overflow: hidden;
  border: 2px solid var(--deep);
  border-radius: 18px;
  background: rgba(255,249,236,.78);
  box-shadow: 7px 8px 0 rgba(59,41,63,.12);
}

.rhythm-card div {
  display: grid;
  grid-template-columns: 42px minmax(94px, .8fr) 1.4fr;
  align-items: center;
  min-height: 59px;
  padding: 10px 14px;
  border-bottom: 1px dashed rgba(59,41,63,.24);
}

.rhythm-card div:last-child { border-bottom: 0; }
.rhythm-card b { color: var(--coral); font: 900 .78rem/1 ui-monospace, monospace; }
.rhythm-card span { font-weight: 900; }
.rhythm-card small { color: #6e6070; font-weight: 700; }

.keyboard-guide {
  margin: 22px 0 0;
  color: #716373;
  font-size: .78rem;
  font-weight: 700;
  line-height: 1.8;
}

kbd {
  display: inline-grid;
  min-width: 24px;
  min-height: 24px;
  margin-inline: 2px;
  place-items: center;
  border: 1px solid rgba(59,41,63,.34);
  border-bottom-width: 3px;
  border-radius: 5px;
  background: var(--cream);
  color: var(--deep);
  font: 800 .7rem/1 ui-monospace, monospace;
}

.status-line {
  min-height: 3.4em;
  margin: 14px 0 0;
  padding-left: 15px;
  border-left: 4px solid var(--mint);
  color: #4f4053;
  font-size: .9rem;
  font-weight: 800;
  line-height: 1.7;
}

.play-panel {
  overflow: hidden;
  border: 3px solid var(--deep);
  border-radius: 27px;
  background: var(--cream);
  box-shadow: 12px 14px 0 rgba(59,41,63,.15);
}

.game-readout {
  display: grid;
  grid-template-columns: .9fr .9fr 1.2fr 1.1fr;
  border-bottom: 2px solid var(--deep);
  background: #443049;
  color: #fff9ec;
}

.game-readout > div {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  min-width: 0;
  padding: 12px 14px 11px;
  border-right: 1px solid rgba(255,255,255,.16);
}

.game-readout > div:last-child { border-right: 0; }
.game-readout span { grid-column: 1 / -1; color: #d9bfd9; font: 900 .62rem/1.3 ui-monospace, monospace; letter-spacing: .12em; }
.game-readout strong { overflow: hidden; font: 950 clamp(1.2rem, 3vw, 1.65rem)/1 ui-monospace, monospace; text-overflow: ellipsis; }
.game-readout small { margin-left: 4px; color: #e9dce9; font: 800 .58rem/1 ui-monospace, monospace; }
.hidden-readout strong { color: #8ee0b8; }
.score-readout strong { color: #ffd978; font-size: clamp(1rem, 2.4vw, 1.42rem); }
.covered-readout strong { color: #ff9a87; font-size: clamp(1rem, 2.4vw, 1.42rem); }

.arena-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background: var(--desk);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
  cursor: grab;
}

canvas:active { cursor: grabbing; }
canvas:focus-visible { box-shadow: inset 0 0 0 5px #fff, inset 0 0 0 8px var(--violet); }

.stage-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(50,34,55,.36);
  backdrop-filter: blur(3px);
}

.stage-overlay[hidden] { display: none; }

.overlay-card {
  width: min(340px, 100%);
  padding: 26px 25px 24px;
  border: 3px solid var(--deep);
  border-radius: 23px;
  background: var(--cream);
  box-shadow: 9px 10px 0 rgba(59,41,63,.22);
  text-align: center;
}

.overlay-kicker {
  margin: 0 0 13px;
  color: #8a5061;
  font: 900 .68rem/1 ui-monospace, monospace;
  letter-spacing: .14em;
}

.overlay-card h2 { margin: 14px 0 10px; font-size: 1.7rem; line-height: 1.15; }
.overlay-card > p:not(.overlay-kicker, .result-count) { margin: 0 0 18px; color: #655567; font-size: .88rem; font-weight: 700; line-height: 1.7; }
.overlay-card > small { display: block; margin-top: 12px; color: #786b78; font-size: .7rem; font-weight: 700; line-height: 1.5; }

.envelope-mark {
  position: relative;
  width: 90px;
  height: 58px;
  margin: 8px auto 4px;
  border: 3px solid var(--deep);
  border-radius: 7px;
  background: #ffd28d;
  box-shadow: 5px 6px 0 rgba(59,41,63,.14);
}

.envelope-mark::before {
  position: absolute;
  inset: 0;
  background: #fff1c9;
  clip-path: polygon(0 0, 50% 65%, 100% 0);
  content: "";
}

.envelope-mark span {
  position: absolute;
  z-index: 2;
  right: 9px;
  bottom: 8px;
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  background: var(--coral);
  color: white;
  font: 950 1rem/1 ui-monospace, monospace;
}

.primary-button {
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  border: 2px solid var(--deep);
  border-radius: 999px;
  background: var(--coral);
  color: #fff;
  box-shadow: 0 5px 0 var(--deep);
  cursor: pointer;
  font-weight: 950;
  letter-spacing: .03em;
  transition: transform .12s ease, box-shadow .12s ease;
}

.primary-button:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--deep); }
.primary-button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--deep); }

.result-count { display: flex; align-items: baseline; justify-content: center; gap: 5px; margin: 8px 0 13px; }
.result-count strong { color: var(--coral); font: 950 3.8rem/1 ui-monospace, monospace; }
.result-count span { font-weight: 900; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.result-stats span { padding: 9px 6px; border-radius: 9px; background: #eee3d6; color: #6b5b6c; font-size: .72rem; font-weight: 800; }
.result-stats b { display: block; margin-top: 3px; color: var(--deep); font-size: 1rem; }

.stage-callout {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 18%;
  padding: 7px 13px;
  border: 2px solid var(--deep);
  border-radius: 999px;
  background: rgba(255,249,236,.96);
  color: var(--deep);
  opacity: 0;
  pointer-events: none;
  font-size: .74rem;
  font-weight: 950;
  transform: translate(-50%, 8px) rotate(-2deg);
  transition: opacity .14s ease, transform .14s ease;
}

.stage-callout.is-visible { opacity: 1; transform: translate(-50%, 0) rotate(-2deg); }

.rule-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  border-top: 2px solid var(--deep);
  background: #fff9ec;
}

.rule-strip div {
  display: grid;
  min-width: 0;
  min-height: 58px;
  align-content: center;
  padding: 10px 12px;
  border-right: 1px dashed rgba(59,41,63,.24);
  text-align: center;
}
.rule-strip div:last-child { border-right: 0; }
.rule-strip span { color: #917f90; font: 900 .56rem/1.2 ui-monospace, monospace; letter-spacing: .08em; }
.rule-strip b { margin-top: 4px; color: var(--deep); font-size: .73rem; line-height: 1.25; }
.rule-strip div:nth-child(2) b { color: #b43e47; }
.rule-strip div:nth-child(3) b { color: #6b547f; }

footer {
  display: flex;
  justify-content: space-between;
  min-height: 68px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: #796a78;
  font: 800 .65rem/1.4 ui-monospace, monospace;
  letter-spacing: .09em;
}

.help-dialog {
  width: min(600px, calc(100% - 32px));
  max-height: min(720px, calc(100vh - 32px));
  padding: 28px;
  overflow: auto;
  border: 3px solid var(--deep);
  border-radius: 22px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 12px 14px 0 rgba(30,20,33,.25);
}

.help-dialog::backdrop { background: rgba(35,22,39,.62); backdrop-filter: blur(3px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading .eyebrow { margin: 0; }
.dialog-close { width: 44px; height: 44px; border: 2px solid var(--deep); border-radius: 50%; background: #fff; cursor: pointer; font-size: 1.4rem; font-weight: 900; }
.help-dialog h2 { margin: 14px 0 22px; font-size: 2rem; }
.help-dialog ol { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.help-dialog li { display: grid; grid-template-columns: 42px 1fr; gap: 12px; align-items: start; }
.help-dialog li > span { display: grid; width: 39px; height: 39px; place-items: center; border-radius: 50%; background: var(--coral); color: white; font: 900 .72rem/1 ui-monospace, monospace; }
.help-dialog li p { margin: 5px 0 0; color: #5d4d60; font-size: .88rem; font-weight: 700; line-height: 1.7; }
.help-dialog > p { margin: 22px 0 0; padding: 13px 15px; border-radius: 11px; background: #eee3d6; font-size: .82rem; font-weight: 800; line-height: 1.7; }

button:focus-visible, a:focus-visible { outline: 4px solid rgba(100,185,148,.55); outline-offset: 4px; }

@media (max-width: 860px) {
  .game-layout { grid-template-columns: 1fr; gap: 34px; width: min(620px, calc(100% - 28px)); padding-top: 34px; }
  .game-copy { text-align: center; }
  .lead { margin-top: 24px; }
  .rhythm-card, .keyboard-guide, .status-line { text-align: left; }
  .play-panel { width: min(560px, 100%); margin-inline: auto; }
  footer { width: min(620px, calc(100% - 28px)); }
}

@media (max-width: 520px) {
  .page-shell { width: calc(100% - 24px); }
  .topbar { min-height: 64px; font-size: .66rem; }
  .topbar-actions { gap: 12px; }
  .topbar-actions > span { display: none; }
  .game-layout { width: calc(100% - 16px); padding-block: 26px 38px; }
  h1 { font-size: clamp(3.8rem, 21vw, 5.8rem); }
  .lead br { display: none; }
  .rhythm-card div { grid-template-columns: 35px minmax(89px, .9fr) 1.35fr; padding-inline: 11px; }
  .rhythm-card small { font-size: .67rem; }
  .play-panel { border-width: 2px; border-radius: 20px; box-shadow: 7px 8px 0 rgba(59,41,63,.14); }
  .game-readout > div { padding: 10px 8px; }
  .game-readout span { font-size: .54rem; }
  .game-readout strong { font-size: 1.02rem; }
  .score-readout strong, .covered-readout strong { font-size: .9rem; }
  .game-readout small { font-size: .5rem; }
  .stage-overlay { padding: 17px; }
  .overlay-card { padding: 21px 19px 20px; }
  .overlay-card h2 { font-size: 1.48rem; }
  .rule-strip div { min-height: 55px; padding-inline: 5px; }
  .rule-strip span { font-size: .48rem; }
  .rule-strip b { font-size: .63rem; }
  footer { flex-direction: column; gap: 5px; padding-bottom: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
  }
}
