/* ------------------------------------------------------------------------ */
/* Tokens                                                                    */
/* ------------------------------------------------------------------------ */

:root {
  /* The page is the manga paper: a white, single-scene look in every theme. */
  color-scheme: light;

  --bg: #ffffff;
  --ink: #161616;
  --muted: #8a8a85;
  --line: #e4e4df;
  --paper: #ffffff;
  --scrim: rgba(255, 255, 255, 0.82);

  --font: "Inter", system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* ------------------------------------------------------------------------ */
/* Base                                                                      */
/* ------------------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------------------ */
/* Layout                                                                    */
/* ------------------------------------------------------------------------ */

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  height: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
}

.stage-frame {
  display: grid;
  place-items: center;
  min-height: 0;
}

/* Shrink-wraps the canvas so the overlay lines up with the picture. */
.stage {
  position: relative;
  display: grid;
  place-items: center;
}

.stage-canvas {
  display: block;
  background: var(--paper);
  touch-action: none;
}

/* ------------------------------------------------------------------------ */
/* Top bar                                                                   */
/* ------------------------------------------------------------------------ */

/* Three columns keep the timer centred while the restart button sits right. */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.clock {
  grid-column: 2;
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.timer {
  font-size: 0.85rem;
}

.best {
  font-size: 0.7rem;
  opacity: 0.7;
}

.topbar .icon-button {
  justify-self: end;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease;
}

.icon-button:hover {
  color: var(--ink);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------------------ */
/* Overlay (always over the white manga panel, so it uses fixed ink colors)  */
/* ------------------------------------------------------------------------ */

.status {
  position: absolute;
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.status.is-error {
  color: #c0392b;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  color: #161616;
  background: var(--scrim);
}

.overlay-title {
  margin: 0 0 8px;
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  font-weight: 700;
}

.overlay-body {
  margin: 0 0 18px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #6b6b66;
}

.overlay-detail {
  display: block;
}

.overlay-button {
  padding: 8px 22px;
  border: 1.5px solid #161616;
  border-radius: 999px;
  background: #161616;
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.overlay-button:hover {
  background: transparent;
  color: #161616;
}

.overlay-button:focus-visible {
  outline-color: #161616;
}

/* The result sits in the empty bottom-right corner, leaving the scene visible. */
.overlay[data-variant="result"] {
  place-items: end end;
  text-align: right;
  background: none;
  pointer-events: none;
}

.overlay[data-variant="result"] .overlay-content {
  pointer-events: auto;
}

.overlay[data-variant="result"] .overlay-title {
  margin-bottom: 2px;
}

.overlay[data-variant="result"] .overlay-body {
  margin-bottom: 10px;
  font-family: var(--font-mono);
}

/* ------------------------------------------------------------------------ */
/* Controls: keyboard legend (desktop) or rocker pad (touch)                 */
/* ------------------------------------------------------------------------ */

.controls {
  display: grid;
  gap: 10px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 28px;
}

.legend-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-label {
  margin-right: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.key {
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: background 0.08s ease, color 0.08s ease, border-color 0.08s ease;
}

.key.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}

.touch-pad {
  display: none;
}

.is-touch .legend {
  display: none;
}

.is-touch .touch-pad {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

/* An odd rocker out spans the whole row instead of leaving a hole. */
.is-touch .rocker:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.rocker {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  height: 56px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.rocker-half {
  border: 0;
  background: none;
  font-size: 1.35rem;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.08s ease, color 0.08s ease;
}

.rocker-half.is-active {
  background: var(--ink);
  color: var(--bg);
}

.rocker-face {
  display: grid;
  place-items: center;
  align-content: center;
  min-width: 64px;
  pointer-events: none;
}

.rocker-emoji {
  font-size: 1.4rem;
  line-height: 1;
}

.rocker-label {
  font-size: 0.65rem;
  color: var(--muted);
}

/* The body part wiggles while its joint is moving. */
.rocker:has(.is-active) .rocker-emoji {
  animation: wiggle 0.28s ease-in-out infinite alternate;
}

@keyframes wiggle {
  from {
    transform: rotate(-14deg) scale(1.1);
  }
  to {
    transform: rotate(14deg) scale(1.1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rocker:has(.is-active) .rocker-emoji {
    animation: none;
  }
}

.credit {
  margin: 0;
  font-size: 0.7rem;
  text-align: center;
  color: var(--muted);
}

.credit a {
  color: inherit;
  text-underline-offset: 2px;
}

.credit a:hover {
  color: var(--ink);
}

/* ------------------------------------------------------------------------ */
/* Small screens                                                             */
/* ------------------------------------------------------------------------ */

@media (max-width: 600px) {
  .app {
    grid-template-rows: auto auto auto;
    align-content: start;
    gap: 16px;
    height: auto;
    min-height: 100%;
  }

  .stage-frame {
    height: min(72vw, 55vh);
  }

  .overlay-body {
    margin-bottom: 12px;
    font-size: 0.8rem;
  }

  /* Keyboard details don't fit a phone; the touch hint is short and needed. */
  :root:not(.is-touch) .overlay-detail {
    display: none;
  }
}
