@font-face {
  font-family: "RobotoGame";
  src: url("fonts/Roboto-VariableFont_wdth,wght.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 75% 100%;
  font-display: swap;
}

@font-face {
  font-family: "FFComma";
  src: url("../../assets/FFCommaTrial-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light;
  --page: #ffffff;
  --panel: #ffffff;
  --ink: #000000;
  --muted: #4a4a4a;
  --line: #000000;
  --soft: #ffffff;
  --accent: #000000;
  --pass: #000000;
  --fail: #000000;
  --rule-width: 3px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #000000;
  --panel: #000000;
  --ink: #ffffff;
  --muted: #c4c4c4;
  --line: #ffffff;
  --soft: #000000;
  --accent: #ffffff;
  --pass: #ffffff;
  --fail: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-family: "FFComma", Georgia, serif;
}

button, select, input { font: inherit; }
button, select { border-radius: 0; }
a { color: inherit; }

.site-header,
main,
footer {
  width: min(1180px, calc(100% - 32px));
  margin-inline: auto;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  padding: 30px 0 22px;
  border-bottom: var(--rule-width) solid var(--ink);
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px 18px;
  max-width: 520px;
}

.back-link {
  font-size: .95rem;
  text-underline-offset: 4px;
}

.back-link:hover,
.back-link:focus-visible { text-decoration-thickness: 2px; }

.theme-toggle {
  min-height: 34px;
  padding: 6px 10px;
  border: var(--rule-width) solid var(--ink);
  background: var(--panel);
  color: var(--ink);
  font-size: .9rem;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(2rem, 5vw, 4rem); letter-spacing: -0.03em; }
h2 { margin-bottom: 0; }
.eyebrow, .label { margin-bottom: 7px; color: var(--muted); font-size: 0.76rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.subtitle { margin-bottom: 0; color: var(--muted); }
.database-summary { max-width: 330px; color: var(--muted); text-align: right; line-height: 1.45; }

.panel {
  background: var(--panel);
  border: var(--rule-width) solid var(--line);
}

.controls-panel { padding: 18px; margin-bottom: 16px; }
.control-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
select,
input[type="text"] {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
output { float: right; color: var(--ink); }

.axes {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  gap: 18px;
  align-items: end;
  margin-top: 17px;
  padding-top: 17px;
  border-top: 2px solid var(--line);
}
.axes p { margin: 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.axes.is-locked input { opacity: .45; }

.game-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.canvas-card { padding: 18px; min-width: 0; }
.card-heading { min-height: 55px; display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.card-heading h2 { font-size: 1.05rem; }
.axis-badge { padding: 7px 9px; border: 2px solid var(--line); background: var(--soft); color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .76rem; white-space: nowrap; }

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  margin-top: 12px;
  border: 2px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}
canvas { display: block; width: 100%; height: 100%; }
.drawing-wrap canvas { cursor: crosshair; touch-action: none; }
.hidden-target-message {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
  letter-spacing: .04em;
}
.target-wrap.is-hidden .hidden-target-message { display: grid; }

.glyph-meta { display: flex; justify-content: space-between; gap: 14px; margin-top: 12px; color: var(--muted); font-size: .82rem; }
.glyph-meta span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button {
  min-height: 40px;
  padding: 9px 14px;
  border: 2px solid var(--ink);
  cursor: pointer;
  font-weight: 700;
}
button:disabled { cursor: not-allowed; opacity: .45; }
button.primary { background: var(--ink); color: var(--page); }
button.secondary { background: var(--panel); color: var(--ink); border-color: var(--line); }
button:hover:not(:disabled) { outline: 2px solid var(--ink); outline-offset: 1px; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.action-row { display: grid; grid-template-columns: 1fr auto; gap: 9px; margin-top: 12px; }

.result-panel { margin-top: 16px; padding: 18px; }
.result-panel.pass { border-color: var(--pass); }
.result-panel.fail { border-color: var(--fail); }
.score-block { display: flex; align-items: center; gap: 18px; }
.score-number { min-width: 100px; font-size: 3.1rem; font-weight: 800; letter-spacing: -.06em; }
.score-block p { margin: 5px 0 0; color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.metric-grid div { display: flex; justify-content: space-between; gap: 10px; padding: 12px; background: var(--soft); border: 2px solid var(--line); }
.metric-grid span { color: var(--muted); font-size: .82rem; }
details { margin-top: 16px; border-top: 2px solid var(--line); padding-top: 14px; }
summary { cursor: pointer; font-weight: 700; }
.debug-layout { display: grid; grid-template-columns: 256px 1fr; gap: 18px; align-items: center; margin-top: 14px; }
.debug-layout canvas { width: 256px; height: 256px; border: 2px solid var(--line); image-rendering: pixelated; }
.debug-layout p { color: var(--muted); line-height: 1.55; }

.ranking-panel { margin-top: 16px; padding: 18px; }
.ranking-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.rank-jump { width: min(340px, 45%); }
.glyph-strip { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 7px; margin-top: 18px; }
.glyph-button { min-height: 74px; padding: 5px; background: var(--panel); color: var(--ink); border: 2px solid var(--line); }
.glyph-button .symbol { display: block; font-family: "RobotoGame", sans-serif; font-size: 2rem; font-variation-settings: "wght" 400, "wdth" 100; }
.glyph-button .rank { display: block; margin-top: 3px; color: var(--muted); font: 10px ui-monospace, SFMono-Regular, Consolas, monospace; }
.glyph-button.current { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: -3px; }
.ranking-note { margin: 14px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.5; }

footer { padding: 24px 0 42px; color: var(--muted); font-size: .78rem; text-align: center; }

@media (max-width: 850px) {
  .site-header { align-items: start; flex-direction: column; }
  .header-actions { width: 100%; max-width: none; justify-content: flex-start; }
  .database-summary { text-align: left; }
  .control-grid { grid-template-columns: 1fr 1fr; }
  .axes { grid-template-columns: 1fr 1fr; }
  .axes p { grid-column: 1 / -1; }
  .game-grid { grid-template-columns: 1fr; }
  .glyph-strip { grid-template-columns: repeat(8, 1fr); }
}

@media (max-width: 540px) {
  .site-header, main, footer { width: min(100% - 18px, 1180px); }
  .site-header { padding-top: 24px; }
  .header-actions { align-items: flex-start; flex-direction: column; gap: 10px; }
  .database-summary { max-width: none; }
  .control-grid, .axes, .metric-grid { grid-template-columns: 1fr; }
  .axes p { grid-column: auto; }
  .debug-layout { grid-template-columns: 1fr; }
  .debug-layout canvas { width: min(256px, 100%); height: auto; }
  .ranking-heading { align-items: stretch; flex-direction: column; }
  .rank-jump { width: 100%; }
  .glyph-strip { grid-template-columns: repeat(5, 1fr); }
}
