@font-face {
  font-family: Galmuri;
  src: url('../ai-arena/font.woff2') format('woff2');
  font-display: swap;
}

* { box-sizing: border-box; }
body {
  --accent: #8bf1d7;
  --ink: #f3f0ff;
  --line: #4b5375;
  --panel: #151b31;
  margin: 0;
  background: radial-gradient(ellipse at top, #293250, #110f23 65%);
  color: var(--ink);
  font: 15px/1.5 Galmuri, system-ui, sans-serif;
  min-height: 100dvh;
}
body[data-game="totem-breaker"] { --accent: #ffd69a; }
body[data-game="seesaw-jump"] { --accent: #ffe2a7; }
body[data-game="yut-ai"] { --accent: #ffce9d; }
body[data-game="lucky-five"] { --accent: #eac9ff; }
body[data-game="slingshot-range"] { --accent: #a1e6ff; }
body[data-game="arrow-rush"] { --accent: #f5bafb; }

main { max-width: 760px; margin: auto; padding: 16px; }
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font-size: clamp(19px, 5vw, 27px); color: var(--accent); }
button, select {
  font: inherit;
  color: var(--ink);
  background: #222c47;
  border: 1px solid #657291;
  border-radius: 8px;
  min-height: 44px;
  padding: 8px 14px;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: .44; cursor: default; }
button:not(:disabled):hover, select:hover { border-color: var(--accent); }
:where(button, select):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#new { flex: none; }
#status {
  color: #f3eeff;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 9px 12px;
  margin: 6px 0 10px;
  min-height: 42px;
  font-variant-numeric: tabular-nums;
}
#controls, #options { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
#controls button {
  flex: 1;
  min-width: 65px;
  min-height: 50px;
  background: var(--accent);
  border-color: transparent;
  color: #171b31;
}
#controls button:not(:disabled):hover { filter: brightness(1.1); }
#options > div { display: flex; gap: 6px; flex-wrap: wrap; }
.help { color: #c6c8df; font-size: 13px; margin: 10px 0 0; }
#board {
  overflow: hidden;
  border: 1px solid #626c90;
  border-radius: 14px;
  background: #131c31;
  box-shadow: 0 8px 22px #0a0c1f60;
}
canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 65vh;
  object-fit: contain;
}
body[data-game="slingshot-range"] canvas { cursor: crosshair; touch-action: none; }
body[data-game="sky-stack"] canvas { touch-action: manipulation; }
#sequence { display: flex; justify-content: center; gap: 5px; margin: 8px 0; }
.arrow {
  display: grid;
  place-items: center;
  flex: 0 1 49px;
  min-width: 0;
  height: clamp(29px, 8vw, 44px);
  font-size: clamp(18px, 5vw, 30px);
  line-height: 1;
  background: #2b3154;
  border: 1px solid #67749b;
  border-radius: 8px;
}
.arrow.done { background: #244347; color: #9aebcb; }
.arrow.current { background: var(--accent); border-color: var(--accent); color: #201b34; }

@media (max-width: 500px) {
  main { padding: 10px; }
  button, select { padding: 8px 10px; }
  #sequence { gap: 3px; }
  #controls {
    position: sticky;
    bottom: 0;
    background: #161329;
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    margin-bottom: 0;
    z-index: 3;
  }
  #status { font-size: 13px; }
  select { max-width: 100%; }
}

@media (max-height: 500px) and (orientation: landscape) {
  main { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 6px 14px; }
  header, #options, #status, #sequence, #controls, .help { grid-column: 2; margin: 0; }
  h1 { font-size: 18px; }
  #board { grid-column: 1; grid-row: 1 / 8; align-self: center; }
  canvas { max-height: 90vh; }
  #sequence { gap: 2px; }
  .arrow { font-size: 18px; }
  #controls { position: static; padding: 0; }
  #controls button { flex-basis: 36%; }
  #status, .help { font-size: 12px; }
}

[hidden] { display: none !important; }
body[data-game="lucky-five"] #board,
body[data-game="yut-ai"] #board {
  position: relative;
  margin-inline: auto;
}
body[data-game="lucky-five"] #board { width: min(100%, calc(65vh * 7 / 6)); }
body[data-game="yut-ai"] #board { width: min(100%, calc(65vh * 35 / 31)); }
body[data-game="lucky-five"] canvas,
body[data-game="yut-ai"] canvas { max-height: none; }
.lucky-door, .yut-token, .yut-destination, .lucky-retry {
  position: absolute;
  transform: translate(-50%, -50%);
}
.lucky-door {
  width: max(44px, 11%);
  height: max(36px, 12%);
  min-height: 0;
  overflow: hidden;
  padding: 0;
  color: transparent;
  border: 2px solid #fff1aa;
  background: #f8d57b1c;
}
.lucky-door:hover, .lucky-door:focus-visible { background: #f8d57b48; }
.lucky-retry {
  left: 50%;
  top: 52%;
  width: min(210px, 75%);
  border: 2px solid #ffedb7;
  background: #392a55;
  font-weight: bold;
  box-shadow: 0 4px 14px #100b24a0;
}
.yut-markers { position: absolute; inset: 0; pointer-events: none; }
.yut-token, .yut-destination {
  padding: 0;
  min-height: 44px;
  pointer-events: auto;
  border-radius: 50%;
}
.yut-token {
  width: 44px;
  color: transparent;
  background: transparent;
  border: 2px solid #affad3;
}
.yut-token[aria-pressed="true"] {
  border-color: #fff7c8;
  box-shadow: 0 0 0 3px #edba7270;
}
.yut-destination {
  width: 48px;
  background: #294e45f0;
  border: 2px dashed #fce2a2;
  font-size: 12px;
}
.yut-results button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}
.target-values span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 7px;
  background: var(--panel);
}
.target-values img { width: 24px; height: 24px; object-fit: contain; }
.ranking {
  margin-top: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.ranking summary { cursor: pointer; color: var(--accent); }
.ranking p { margin: 5px 0; }
.ranking ol { margin: 8px 0; }
.ranking ol:empty, .ranking p:empty { display: none; }

@media (max-height: 500px) and (orientation: landscape) {
  body[data-game="lucky-five"] #board { width: min(100%, calc(90vh * 7 / 6)); }
  body[data-game="yut-ai"] #board { width: min(100%, calc(90vh * 35 / 31)); }
  .ranking { grid-column: 2; margin: 0; }
}

.ranking-form { display: flex; flex-wrap: wrap; gap: .6rem; margin: .65rem 0; align-items: center; }
.ranking-form input { min-width: 8rem; max-width: 13rem; flex: 1; padding: .6rem; color: var(--ink); background: #151b2d; border: 1px solid var(--line); border-radius: .5rem; font: inherit; }
.ranking-refresh { margin: .65rem 0 0; }
.ranking li { margin-block: .25rem; overflow-wrap: anywhere; }
