:root {
  --bg: #05060a;
  --fg: #ece6d6;
  --muted: #9a958a;
  --panel: rgba(12, 14, 22, 0.78);
  --line: rgba(255, 255, 255, 0.12);
  --nova: #4fb3ff;
  --gold: #f2b54a;
  --umbra: #ff3b2f;
  --target-size: 24px;
  color-scheme: dark;
}
@media (pointer: coarse) {
  :root { --target-size: 44px; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif; }
body { overflow-wrap: break-word; -webkit-tap-highlight-color: transparent; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2; pointer-events: none;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.8rem;
  padding: max(0.5rem, env(safe-area-inset-top, 0px)) max(0.75rem, env(safe-area-inset-right, 0px)) 0.4rem max(0.75rem, env(safe-area-inset-left, 0px));
  background: linear-gradient(to bottom, rgba(5, 6, 10, 0.85), rgba(5, 6, 10, 0));
}
.title { display: flex; flex-direction: column; line-height: 1.1; }
.t-ja { font-weight: 700; letter-spacing: 0.08em; font-size: 1rem; }
.t-en { font-size: 0.66rem; letter-spacing: 0.35em; color: var(--gold); }
.status { pointer-events: auto; display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.8rem;
  border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 0.95rem; }
.dot { inline-size: 0.8rem; block-size: 0.8rem; border-radius: 50%; background: #eee; box-shadow: 0 0 8px var(--nova); }
.dot.b { background: #111; border: 1px solid #555; box-shadow: 0 0 8px var(--umbra); }
.check { color: #fff; background: var(--umbra); padding: 0.1rem 0.5rem; border-radius: 6px; font-weight: 700;
  animation: pulse 0.9s ease-in-out infinite alternate; }
.thinking { color: var(--gold); font-size: 0.85rem; }
@keyframes pulse { from { box-shadow: 0 0 2px var(--umbra); } to { box-shadow: 0 0 14px var(--umbra); } }
@media (prefers-reduced-motion: reduce) { .check { animation: none; } }
.captured { font-size: 1.15rem; display: flex; gap: 0.8rem; margin-inline-start: auto; }
#capByWhite { color: #ddd; } #capByBlack { color: #aaa; }

#side {
  position: fixed; z-index: 2; right: max(0.75rem, env(safe-area-inset-right, 0px)); top: 5.2rem;
  inline-size: 13rem; max-block-size: calc(100dvh - 12rem); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0.5rem 0.6rem;
  font-variant-numeric: tabular-nums;
}
.side-head { font-weight: 700; padding-block-end: 0.3rem; border-block-end: 1px solid var(--line); }
.small { font-size: 0.75rem; color: var(--muted); font-weight: 400; }
#moves { margin: 0.3rem 0 0; padding-inline-start: 2.2rem; font-size: 0.9rem; line-height: 1.6; }
#moves li span { display: inline-block; min-inline-size: 4.2em; }
#moves li span.last { color: var(--gold); font-weight: 700; }

.toolbar {
  position: fixed; z-index: 2; left: 0; right: 0; bottom: 1.4rem;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem;
  padding: 0.4rem max(0.6rem, env(safe-area-inset-right, 0px)) max(0.4rem, env(safe-area-inset-bottom, 0px)) max(0.6rem, env(safe-area-inset-left, 0px));
}
.toolbar button, dialog button {
  min-block-size: max(var(--target-size), 2.9rem); min-inline-size: max(var(--target-size), 3.6rem);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.1rem;
  padding: 0.3rem 0.65rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--fg); font: inherit; font-size: 0.82rem; cursor: pointer;
  touch-action: manipulation;
}
.toolbar button:hover, dialog button:hover { border-color: var(--gold); }
.toolbar button:focus-visible, dialog button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.toolbar button[aria-pressed="true"] { border-color: var(--nova); box-shadow: 0 0 10px rgba(79, 179, 255, 0.4); }
.ic { font-size: 1.1rem; line-height: 1; }
.only-narrow { display: none !important; }

.credit { position: fixed; z-index: 2; left: 0; right: 0; bottom: 0; text-align: center; font-size: 0.68rem;
  color: var(--muted); padding: 0.1rem 0.5rem max(0.15rem, env(safe-area-inset-bottom, 0px)); }
.credit a { color: var(--muted); }

.loading { position: fixed; inset: 0; z-index: 5; display: grid; place-content: center; justify-items: center; gap: 1rem;
  background: var(--bg); transition: opacity 0.5s; }
.loading.done { opacity: 0; pointer-events: none; }
.spinner { inline-size: 3rem; block-size: 3rem; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--nova);
  animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { background: rgba(14, 16, 26, 0.96); color: var(--fg); border: 1px solid var(--line); border-radius: 16px;
  padding: 1.1rem 1.2rem; max-inline-size: min(26rem, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); overflow: hidden; overscroll-behavior: contain; }
dialog:modal { overscroll-behavior: contain; }
dialog h1 { font-size: 1.15rem; margin: 0 0 0.8rem; text-wrap: balance; }
.promo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
.promo-grid button { font-size: 0.95rem; min-block-size: 4.5rem; }
.glyph { font-size: 1.8rem; line-height: 1; }
.row { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: flex-end; margin-block-start: 0.8rem; }
.row button { flex-direction: row; padding-inline: 1rem; font-size: 0.95rem; }
.settings { display: grid; gap: 0.4rem; }
.opt { display: flex; align-items: center; gap: 0.6rem; min-block-size: var(--target-size); }
.opt input { inline-size: 1.25rem; block-size: 1.25rem; }
.lore p { margin: 0.6rem 0 0; }
.set-pick { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 0.3rem; padding: 0.2rem 0.8rem 0.4rem; }
.set-pick legend { padding: 0 0.3rem; color: var(--gold); }
.nova { color: var(--nova); } .umbra { color: var(--umbra); }

/* narrow screens (phones): move list becomes a toggleable sheet above the toolbar */
@media (max-width: 820px) {
  .only-narrow { display: inline-flex !important; }
  #side { display: none; left: max(0.75rem, env(safe-area-inset-left, 0px)); right: max(0.75rem, env(safe-area-inset-right, 0px));
    inline-size: auto; top: auto; bottom: calc(9.5rem + env(safe-area-inset-bottom, 0px)); max-block-size: 30dvh; }
  #side.open { display: block; }
  .toolbar button { min-inline-size: max(var(--target-size), 3.3rem); padding-inline: 0.4rem; font-size: 0.75rem; }
  .captured { inline-size: 100%; margin-inline-start: 0; font-size: 1rem; }
  .status { font-size: 0.88rem; }
}
