@font-face {
  font-family: Biscuit Display;
  src: url("./assets/display.woff2") format("woff2");
  font-weight: 900;
  font-display: swap;
}
@font-face {
  font-family: Biscuit UI;
  src: url("./assets/ui.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --display: "Biscuit Display", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  --ui: "Biscuit UI", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  --red: #b92038;
  --cream: #fff5df;
  --ink: #482619;
  --muted: #795643;
  font-family: var(--ui);
  background: var(--red);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100svh;
  background:
    radial-gradient(ellipse at 25% 7%, #e54556 0, transparent 60%),
    linear-gradient(143deg, #cf3248, #a1172f 82%);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(136deg, #fff8de24 0 2px, transparent 2px 12px);
  mask-image: linear-gradient(139deg, #000 0%, transparent 24%, transparent 76%, #000 100%);
}
button {
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible, canvas:focus-visible {
  outline: 3px solid #3020a3;
  outline-offset: 4px;
}

.game {
  position: relative;
  width: min(100% - 64px, 1000px);
  margin: 0 auto;
  padding: clamp(26px, 4.2vh, 64px) 0 20px;
}
.heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  color: #fff5df;
}
.heading-copy { min-width: 0; }
.heading-actions { display: flex; flex: none; align-items: center; gap: 8px; }
h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 44px;
  font-weight: 900;
}
.wordmark {
  display: block;
  width: auto;
  height: clamp(79px, 13.6vh, 111px);
  max-width: min(100%, 428px);
  object-fit: contain;
  object-position: left center;
}
.heading p {
  margin: 11px 0 0;
  font-size: clamp(13px, 1.65vw, 16px);
  font-weight: 700;
  line-height: 1.65;
}
.sound-button {
  min-height: 44px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1.5px solid #ffedd6a8;
  border-radius: 25px;
  color: #fff5df;
  background: #86172d4d;
  font-weight: 800;
  font-size: 12px;
}
.sound-button:hover { background: #86172daa; }
.sound-icon {
  display: inline-block;
  position: relative;
  width: 14px;
  height: 15px;
}
.sound-icon::before {
  content: "";
  position: absolute;
  inset: 1px 5px 1px 0;
  background: currentColor;
  clip-path: polygon(0 28%, 39% 28%, 100% 0, 100% 100%, 39% 72%, 0 72%);
}
.sound-icon::after {
  content: "";
  position: absolute;
  right: 0;
  top: 3px;
  width: 7px;
  height: 9px;
  border-right: 1.5px solid currentColor;
  border-radius: 50%;
}
.sound-button[aria-pressed="false"] .sound-icon::after {
  width: 8px;
  height: 2px;
  right: -2px;
  top: 7px;
  border: 0;
  border-radius: 1px;
  background: currentColor;
  transform: rotate(-48deg);
}

.board {
  overflow: hidden;
  border: 2px solid #75212e;
  border-radius: 24px;
  background: var(--cream);
  box-shadow: 0 8px 0 #781426, 0 21px 45px #63102145;
}
.scorebar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  position: relative;
  gap: 16px;
  padding: 14px clamp(20px, 3vw, 34px) 16px;
  background: #fff7e5;
}
.score, .timer {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-weight: 800;
  font-size: 13px;
}
.timer { color: var(--muted); }
.percent, .seconds {
  display: flex;
  align-items: baseline;
  gap: 4px;
  line-height: 1;
  font-family: var(--display);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.percent {
  color: #ae2539;
  font-size: clamp(28px, 4.8vw, 48px);
}
.percent-unit { font-size: .48em; }
.seconds {
  color: var(--ink);
  font-size: clamp(21px, 2.6vw, 28px);
}
.seconds-unit {
  font-family: var(--ui);
  font-size: 12px;
}
.coverage {
  appearance: none;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 4px;
  border: 0;
  background: #ebd7ad;
  color: #d14b46;
}
.coverage::-webkit-progress-bar { background: #ebd7ad; }
.coverage::-webkit-progress-value { background: #d14b46; }
.coverage::-moz-progress-bar { background: #d14b46; }
.game[data-phase="cleared"] .coverage::-webkit-progress-value { background: #c98a14; }
.game[data-phase="cleared"] .coverage::-moz-progress-bar { background: #c98a14; }

.scene {
  height: clamp(226px, min(33vw, 40vh), 345px);
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(ellipse at 46% 45%, #fff7e6, #e6ca9b);
  user-select: none;
}
.scene::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("./assets/tray.webp") center / cover no-repeat;
  pointer-events: none;
}
.scene canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
}
.scene canvas:focus-visible {
  outline-offset: -5px;
  outline-color: #732943;
}
.game[data-input="pointer"] :is(canvas, button):focus-visible { outline: none; }
.scene canvas[data-contact="true"] { cursor: grabbing; }
.start-marker {
  position: absolute;
  width: 52px;
  height: 52px;
  transform: translate(-50%, -50%);
  border: 2px solid #da5266;
  border-radius: 50%;
  box-shadow: 0 0 0 5px #fff7ebae;
  pointer-events: none;
}
.game:not([data-phase="ready"]) .start-marker { display: none; }

.controls, .result {
  position: relative;
  display: flex;
  align-items: center;
  gap: 26px;
  min-height: 90px;
  padding: 16px clamp(20px, 3vw, 34px);
  background: #fff7e5;
  border-top: 1px solid #e3cba7;
}
.meters {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}
.meter-group { min-width: 0; }
.meter-text {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 13px;
  font-weight: 800;
}
#strain-status, #pace-label { color: var(--muted); }
.strain-meter, .pace-meter {
  position: relative;
  height: 13px;
  background: #e8d6b9;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 2px 3px #9d66352c;
}
.strain-meter::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 40%;
  border-left: 2px solid #fff7e5;
  background: repeating-linear-gradient(135deg, #aa253020 0 3px, transparent 3px 7px);
}
.strain-fill {
  width: 100%;
  height: 100%;
  transform: scaleX(var(--strain, 0));
  transform-origin: left;
  background: linear-gradient(90deg, #ecb04b, #ec803b 48%, #d62348);
  border-radius: inherit;
}
.strain-crack {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--damage, 0%);
  background: #aa233a;
}
.pace-target {
  position: absolute;
  inset: 0 auto 0 var(--pace-start, 25%);
  width: var(--pace-width, 5%);
  background: #5d875a;
}
.pace-pointer {
  position: absolute;
  inset: 0 auto 0 var(--pace-position, 0%);
  width: 4px;
  border-radius: 3px;
  background: #562d24;
  box-shadow: 0 0 0 1px #fff5df;
}
.pace-meter[data-locked="true"] .pace-pointer { background: #a72142; }
.game[data-danger="true"] #strain-status { color: #b51e39; }
.text-button {
  min-height: 44px;
  flex: none;
  padding: 0 12px;
  color: #6d4233;
  font-size: 13px;
  font-weight: 800;
  background: transparent;
  border: 1px solid #d2b99b;
  border-radius: 10px;
}
.text-button:hover { background: #f9ead0; }
.result {
  min-height: 107px;
  justify-content: space-between;
}
.result h2 {
  margin: 0;
  color: #aa243a;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(24px, 3.8vw, 39px);
  letter-spacing: -.06em;
  line-height: 1.25;
}
.game[data-phase="cleared"] .result h2 { color: #80520c; }
.result p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
}
.retry {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 50px;
  padding: 0 20px;
  flex: none;
  border: 1px solid #8c1930;
  border-radius: 12px;
  box-shadow: 0 3px 0 #8c1930;
  background: #c72b43;
  color: #fff8e8;
  font-weight: 900;
}
.retry:hover { background: #af2037; }
.retry:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #8c1930;
}
.retry span { font-size: 19px; }
.game-footer {
  min-height: 20px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: #fff0d7;
  margin: 16px 2px 0;
  font-size: 12px;
  font-weight: 700;
}
.game-footer p { margin: 0; }
.rank-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid #ffedd6a8;
  border-radius: 999px;
  background: #92132d40;
  color: var(--cream);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}
.rank-button:hover:not(:disabled) { background: #7f142e; }
.rank-button:disabled { opacity: .55; cursor: default; }
.rank-button:focus-visible { outline-color: var(--cream); }
#rank-result, dialog.mg-dialog {
  --paper: var(--cream);
  --body: var(--ui);
  --numbers: var(--display);
  --blue: #9c1c34;
  --line: #d7aa82;
}
#rank-result {
  display: grid;
  grid-template-columns: minmax(130px, .9fr) minmax(160px, 1.3fr) auto;
  align-items: center;
  gap: 8px 16px;
  padding: 9px 22px 15px;
  border-top: 1px solid #e6d3b1;
  background: #fff5df;
}
#rank-result .mg-standing { height: auto; min-height: 44px; justify-content: center; overflow: visible; text-align: left; }
#rank-result .mg-standing p { margin: 0; }
#rank-result .mg-register input { border-radius: 8px; background: #fffdf7; font-size: 16px; }
#rank-result .mg-register button { border-radius: 8px; background: #9c1c34; color: #fff8e8; border-color: #79152a; }
#rank-result .mg-register button:disabled { opacity: .65; }
#rank-result .mg-ranking-link { padding-inline: 4px; font-size: 13px; }
#rank-result .mg-action-error { grid-column: 1 / -1; }
dialog.mg-dialog {
  height: fit-content;
  max-height: min(680px, calc(100dvh - 24px));
  border: 1.5px solid #8c1930;
  border-top: 5px solid var(--red);
  border-radius: 20px;
  box-shadow: 0 8px 0 #6e142a, 0 20px 55px #3412194a;
}
dialog.mg-dialog::backdrop { background: #331518aa; }
.mg-dialog .mg-dialog-layout {
  display: flex;
  flex-direction: column;
  height: auto;
  max-height: min(625px, calc(100dvh - 68px));
}
.mg-dialog .mg-dialog-layout > :not(.mg-board-content) { flex: none; }
.mg-dialog .mg-dialog-header h2 { font: 900 23px/1.3 var(--ui); }
.mg-dialog .mg-board-content { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.mg-dialog .mg-board-message { min-height: 98px; }
.mg-dialog .mg-close, .mg-dialog .mg-return { border-radius: 9px; border-bottom-color: #bc9168; }
.mg-dialog .mg-board-filter span { background: #962039; border-radius: 5px; }
.mg-dialog .mg-own-record { background: #f8e7cc; border-radius: 9px; }
.mg-dialog .mg-table .mg-own-row { background: #f8ded5 !important; }
.mg-dialog .mg-table tr > :last-child { width: 110px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 650px) {
  .game {
    width: min(100% - 28px, 490px);
    padding-top: clamp(23px, 5vh, 47px);
  }
  .heading {
    position: relative;
    display: block;
    margin-bottom: 15px;
  }
  .wordmark {
    height: 77px;
    max-width: min(100%, 254px);
  }
  .heading p {
    margin-top: 10px;
    padding-right: 2px;
    font-size: 12px;
  }
  .heading p span { display: block; }
  .heading-actions { position: absolute; right: 0; top: -2px; gap: 6px; }
  .sound-button {
    min-width: 44px;
    min-height: 44px;
    padding: 0 9px;
    gap: 0;
  }
  .rank-button { min-width: 44px; padding: 0 9px; }
  h1 { padding-right: 98px; }
  .rank-button span,
  #sound-label { display: none; }
  .board { border-radius: 19px; }
  .scorebar { padding: 12px 15px 14px; }
  .score, .timer {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    font-size: 11px;
  }
  .timer { align-items: flex-end; }
  .scene { height: clamp(238px, 46svh, 392px); }
  .scene::before {
    inset: 50% auto auto 50%;
    width: max(408px, 114%);
    height: 112%;
    transform: translate(-50%, -50%) rotate(-90deg);
  }
  .controls, .result {
    min-height: 75px;
    padding: 12px 15px;
    gap: 12px;
  }
  .meters {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
  .meter-text {
    margin-bottom: 6px;
    font-size: 12px;
  }
  .result h2 { font-size: clamp(22px, 6vw, 29px); }
  .result p { font-size: 12px; }
  .retry {
    gap: 7px;
    padding: 0 11px;
    min-height: 46px;
    font-size: 13px;
  }
  .start-marker { width: 45px; height: 45px; }
  #rank-result {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0 8px;
    padding: 5px 15px 12px;
  }
  #rank-result .mg-standing { grid-row: 1; grid-column: 1; }
  #rank-result .mg-ranking-link { grid-row: 1; grid-column: 2; font-size: 12px; }
  #rank-result .mg-register { grid-column: 1 / -1; }
}
@media (max-width: 350px) {
  .result { flex-wrap: wrap; }
  .retry { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
