@font-face {
  font-family: KKPlex;
  src: url("fonts/IBMPlexMono-Medium.woff") format("woff");
  font-weight: 600;
  font-display: swap;
}

:root {
  --kk-ink: #182125;
  --kk-board: #203337;
  --kk-paper: #f4ead3;
  --kk-muted: #becac1;
  --kk-copper: #f2a271;
  --kk-red: #9c392c;
  --kk-blue: #24565d;
  --kk-lime: #d8ed62;
  --kk-cyan: #a1ece1;
  --kk-mono: KKPlex, "IBM Plex Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--kk-ink);
  color: var(--kk-paper);
  font: 600 14px/1.4 var(--kk-mono);
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }
#game-container { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--kk-ink); }
#kk-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
:is(button, a, input):focus-visible { outline: 2px solid var(--kk-lime); outline-offset: 3px; }

/* Navigation uses the arcade shell's existing handlers and state. */
.arcade-web body[data-arcade=krazkraft] {
  --arcade-ink: var(--kk-ink);
  --arcade-accent: var(--kk-lime);
  --arcade-panel: var(--kk-board);
  --color-border-light: #637770;
  --color-text-primary: var(--kk-paper);
  --color-text-secondary: var(--kk-paper);
  --color-warning: #ffd09b;
  gap: 0;
  background: var(--kk-ink);
  font-family: var(--kk-mono);
}
.arcade-web [data-arcade=krazkraft] .arcade-toolbar {
  display: flex !important;
  flex-wrap: nowrap;
  min-height: 54px;
  padding: 5px clamp(8px, 2vw, 24px);
  gap: 8px;
  background: var(--kk-ink);
  border-bottom: 1px solid #526760;
}
.arcade-web [data-arcade=krazkraft] .arcade-toolbar :is(button, a, img) { border-radius: 0; box-shadow: none; font-family: inherit; }
.arcade-web [data-arcade=krazkraft] .arcade-toolbar :is(button, a) { width: auto; min-width: 44px; min-height: 44px; padding: 6px 10px; }
.arcade-web [data-arcade=krazkraft] .arcade-back .kk-back-label { font-size: 12px; }
.arcade-web [data-arcade=krazkraft] .arcade-identity { flex: 1; gap: 7px; }
.arcade-web [data-arcade=krazkraft] .arcade-identity img { width: 34px; height: 34px; }
.arcade-web [data-arcade=krazkraft] .arcade-tools { width: auto; flex: none; gap: 5px; }
.arcade-web [data-arcade=krazkraft] #arcade-fullscreen { display: inline-flex; }
.arcade-web:fullscreen [data-arcade=krazkraft] #arcade-fullscreen { color: var(--kk-lime); border-color: var(--kk-lime); }
.arcade-web [data-arcade=krazkraft] #arcade-sound[aria-pressed="false"] { color: var(--kk-muted); background: var(--kk-ink); }
.arcade-web body[data-arcade=krazkraft] > #game-container { margin: 0; padding: 0; border: 0; border-radius: 0; }

/* Readouts sit on their own opaque rail, clear of the playfield and board colors. */
#kk-hud { position: absolute; inset: 0 0 auto; z-index: 5; pointer-events: none; }
#kk-readouts {
  display: grid;
  grid-template-columns: minmax(134px, 1.2fr) repeat(4, minmax(0, 1fr)) auto;
  align-items: center;
  gap: 6px;
  padding: 6px clamp(8px, 2vw, 24px) 8px;
  background: var(--kk-ink);
  border-bottom: 2px solid var(--kk-copper);
  font-variant-numeric: tabular-nums;
}
#kk-hud[data-realm="1"] #kk-readouts { border-color: var(--kk-cyan); }
.kk-hud-group { min-width: 0; min-height: 43px; display: grid; align-content: center; padding: 2px 8px; border-left: 1px solid #53665f; }
.kk-vitals { gap: 4px; border-left: 0; padding-left: 0; }
.kk-label { display: block; color: var(--kk-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .045em; }
.kk-integrity, .kk-mana { display: flex; align-items: center; gap: 6px; }
#kk-seals { color: var(--kk-lime); white-space: nowrap; letter-spacing: .07em; font-size: 14px; line-height: 1; }
#kk-mana { min-width: 14px; width: min(100%, 70px); height: 9px; flex: 1; appearance: none; accent-color: var(--kk-cyan); }
#kk-mana::-webkit-meter-bar { border: 0; border-radius: 0; background: #344b50; }
#kk-mana::-webkit-meter-optimum-value { background: var(--kk-cyan); }
#kk-mana::-moz-meter-bar { background: var(--kk-cyan); }
#kk-mana-value { font-size: 11px; }
#kk-clock { font-size: clamp(16px, 2vw, 22px); line-height: 1.15; }
#kk-hud[data-urgent="true"] #kk-clock { color: #ff9d87; }
.kk-memory > div { display: flex; flex-wrap: wrap; column-gap: 8px; }
.kk-memory > div span { white-space: nowrap; }
.kk-memory > div span::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 5px; background: currentColor; transform: rotate(45deg); vertical-align: 1px; }
#kk-folio-count, #kk-realm { color: var(--kk-copper); }
#kk-blueprint-count, #kk-hud[data-realm="1"] #kk-realm { color: var(--kk-cyan); }
#kk-coach {
  width: fit-content;
  max-width: min(680px, calc(100% - 16px));
  margin: 7px auto 0;
  padding: 6px 10px;
  background: var(--kk-ink);
  border-left: 3px solid var(--kk-lime);
  color: var(--kk-paper);
  font-size: 13px;
}
#kk-coach[data-alert="true"] { border-color: #ff9d87; }
#kk-sector-intro {
  position: absolute;
  z-index: 4;
  top: 36%;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 8px 16px;
  transform: translateX(-50%);
  border: 1px solid var(--kk-copper);
  color: var(--kk-paper);
  background: var(--kk-ink);
  text-align: center;
  pointer-events: none;
}
#kk-sector-intro strong { display: block; font-size: clamp(20px, 4vw, 34px); }
#kk-sector-intro span { display: block; font-size: 12px; color: var(--kk-muted); }
#kk-pause-btn {
  position: relative;
  pointer-events: auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #637770;
  background: var(--kk-board);
  color: var(--kk-paper);
  cursor: pointer;
}
#kk-pause-btn::before { content: ""; display: block; width: 12px; height: 16px; margin: auto; border-inline: 4px solid currentColor; }
.arcade-web #kk-pause-btn { display: none; }

/* Menus and result cards use the same copper edge and casing. */
#kk-overlay { position: absolute; inset: 0; display: flex; padding: 12px; overflow: auto; overscroll-behavior: contain; background: #132023d9; z-index: 20; }
#kk-overlay[data-screen="title"] { background: #132023b8; }
.kk-card {
  --card-rule: #a89d83;
  width: min(100%, 530px);
  margin: auto;
  padding: clamp(14px, 3vw, 24px);
  background: var(--kk-paper);
  color: var(--kk-ink);
  border: 1px solid #a89d83;
  border-top: 4px solid var(--kk-copper);
  box-shadow: 6px 6px #111a1e;
}
.kk-card h1, .kk-card h2 { margin: 0; font-weight: 600; line-height: 1.07; letter-spacing: -.06em; }
.kk-card h1 { font-size: clamp(33px, 7vw, 65px); }
.kk-card h2 { font-size: clamp(27px, 6vw, 39px); }
.kk-title-lockup { display: flex; align-items: center; gap: 9px; }
.kk-title-lockup img { width: clamp(40px, 7vw, 55px); height: auto; flex: none; }
.kk-sub { margin: 3px 0 0; color: var(--kk-blue); font-size: 12px; letter-spacing: .055em; text-transform: uppercase; }
.kk-card p { margin: 10px 0; line-height: 1.5; }
.kk-title-lockup .kk-sub { margin: 3px 0 0; }
.kk-card button {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 8px 10px;
  border: 2px solid var(--kk-ink);
  border-radius: 0;
  color: var(--kk-paper);
  background: var(--kk-ink);
  font: inherit;
  cursor: pointer;
}
.kk-card button[data-primary]:not(.kk-card-btn) { color: var(--kk-ink); background: var(--kk-lime); }
.kk-card .kk-quiet { color: var(--kk-ink); background: transparent; }
.kk-card button:hover { color: white; background: var(--kk-red); border-color: var(--kk-red); }
.kk-card button[data-primary]:not(.kk-card-btn):hover { color: var(--kk-paper); background: var(--kk-ink); }
.kk-card :is(button, a, input):focus-visible { outline-color: var(--kk-red); }
.kk-rule { height: 1px; margin: 10px 0; background: var(--card-rule); }
#kk-title { padding: 0; width: min(100%, 810px); display: grid; grid-template-columns: minmax(220px, 1fr) minmax(305px, 1.18fr); }
.kk-title-art { position: relative; overflow: hidden; min-height: 365px; background: #1b3439; }
#kk-cover {
  position: absolute;
  inset: 0 auto 0 50%;
  width: 190.48%;
  height: 100%;
  transform: translateX(-50%);
  object-fit: cover;
  object-position: 50% 48%;
}
.kk-title-body { min-width: 0; padding: clamp(14px, 3vw, 26px); align-self: center; }
.kk-title-actions, .kk-end-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#kk-how { margin: 12px 0 0; padding-top: 7px; border-top: 1px solid var(--card-rule); font-size: 13px; }
#kk-how-device { display: flex; gap: 5px; margin: 0; padding: 0; border: 0; }
#kk-how-device legend { margin-bottom: 4px; padding: 0; }
#kk-how-device label { display: grid; flex: 1; cursor: pointer; }
#kk-how-device input { grid-area: 1 / 1; width: 1px; height: 1px; opacity: 0; }
#kk-how-device label span { grid-area: 1 / 1; display: grid; place-items: center; min-height: 44px; border: 1px solid #7d7766; }
#kk-how-device input:checked + span { color: var(--kk-paper); background: var(--kk-blue); }
#kk-how-device input:focus-visible + span { outline: 2px solid var(--kk-red); outline-offset: 2px; }
#kk-how dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0; }
#kk-how dt { color: var(--kk-red); }
#kk-how dd { margin: 0; }
#kk-ledger { border-top: 1px solid var(--card-rule); margin-top: 12px; padding-top: 6px; font-size: 12px; }
#kk-ledger ol { margin: 4px 0 0; padding-left: 2.3em; }
#kk-ledger .kk-ledger-head { margin: 0; }
.kk-field { display: flex; align-items: center; gap: 9px; min-height: 44px; margin: 8px 0; }
.kk-field input { flex: 1; min-width: 0; height: 44px; accent-color: var(--kk-blue); }
.kk-field output { min-width: 4ch; text-align: right; }
#kk-pause button + button { margin-top: 7px; }
.kk-card table { width: 100%; border-collapse: collapse; margin: 7px 0; font-size: 13px; }
.kk-card th { text-align: left; font-weight: 600; padding: 3px 0; }
.kk-card td { text-align: right; padding: 3px 0 3px 7px; }
.kk-card tr + tr { border-top: 1px dotted var(--card-rule); }
#kk-upgrade-list { display: grid; gap: 6px; }
.kk-card .kk-card-btn { text-align: left; }
.kk-card-btn strong, .kk-card-btn span { display: block; }
.kk-card-btn span { margin-top: 1px; font-size: 12px; }
#kk-end[data-won="1"] { border-top-color: var(--kk-blue); }
#kk-end[data-won="1"] h2 { color: var(--kk-blue); }
#kk-end[data-won="0"] h2 { color: var(--kk-red); }
.kk-end-score-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kk-end-score-line .kk-label { color: var(--kk-blue); }
#kk-end-score { font-size: clamp(29px, 7vw, 42px); line-height: 1.1; }
#kk-end-best { font-size: 12px; }
.kk-stamp { color: var(--kk-red); border: 1px solid currentColor; padding: 3px 8px; }
#kk-end-kredits-row { display: flex; justify-content: space-between; gap: 8px; padding: 6px 9px; color: var(--kk-ink); background: var(--kk-lime); border-left: 3px solid var(--kk-blue); }
#kk-hof { display: inline-flex; align-items: center; min-height: 44px; color: var(--kk-blue); font-size: 13px; }

#kk-touch { display: none; position: absolute; right: 12px; bottom: 12px; z-index: 10; gap: 9px; }
html[data-kk-input="touch"] #kk-touch { display: flex; }
#kk-touch button {
  width: 74px;
  height: 54px;
  padding: 4px;
  border: 2px solid var(--kk-ink);
  border-radius: 0;
  box-shadow: 2px 2px var(--kk-ink);
  color: var(--kk-ink);
  background: var(--kk-paper);
  font: inherit;
  text-transform: uppercase;
  touch-action: none;
  user-select: none;
}
#kk-touch small { display: block; font-size: 10px; }
#kk-touch #kk-flip { background: var(--kk-lime); }
#kk-touch #kk-shard[data-low="true"] { color: var(--kk-paper); background: #425453; }
#kk-touch button:active { box-shadow: inset 0 0 0 2px currentColor; }
@media (pointer: coarse) { #kk-touch { display: flex; } }

@media (max-width: 620px) {
  #kk-title { display: block; max-width: 440px; }
  .kk-title-art { min-height: 0; height: clamp(116px, 28vh, 220px); }
  #kk-readouts { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 2px 4px; }
  .kk-hud-group { min-height: 31px; }
  .kk-vitals, .kk-clock, .kk-memory { grid-column: span 2; }
  .kk-location { grid-column: span 3; border-left: 0; padding-left: 0; }
  .kk-score { grid-column: span 2; }
  .arcade-web .kk-location, .arcade-web .kk-score { grid-column: span 3; }
  .kk-memory > div { column-gap: 5px; }
  .kk-memory > div span::before { width: 6px; height: 6px; margin-right: 3px; }
  .arcade-web [data-arcade=krazkraft] .arcade-back .kk-back-label { display: none; }
  .arcade-web [data-arcade=krazkraft] .arcade-toolbar button { padding: 6px; }
  .arcade-web [data-arcade=krazkraft] #arcade-fullscreen { font-size: 0; }
  .arcade-web [data-arcade=krazkraft] #arcade-fullscreen::before { content: ""; width: 14px; height: 14px; border: 2px dashed currentColor; }
  .arcade-web [data-arcade=krazkraft] #arcade-sound { font-size: 0; }
  .arcade-web [data-arcade=krazkraft] #arcade-sound::before { content: "Sound"; font-size: 11px; }
  .arcade-web [data-arcade=krazkraft] #arcade-sound[aria-pressed="false"]::before { text-decoration: line-through; }
  .arcade-web [data-arcade=krazkraft] .arcade-wallet { padding-inline: 5px; }
}

@media (max-width: 440px) {
  .arcade-web [data-arcade=krazkraft] .arcade-identity strong { display: none; }
}

@media (max-width: 374px) {
  #kk-mana-value { display: none; }
}

@media (max-height: 520px) and (min-width: 621px) {
  #kk-title { max-width: 690px; grid-template-columns: 1fr 1.35fr; }
  .kk-title-art { min-height: 0; }
  #kk-sector-intro { top: 42%; }
  .kk-title-body { padding: 12px 16px; }
  #kk-title:has(#kk-how:not([hidden])) { display: block; }
  #kk-title:has(#kk-how:not([hidden])) .kk-title-art { display: none; }
  #kk-title:has(#kk-how:not([hidden])) .kk-title-body { display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; align-items: start; }
  #kk-how { grid-column: 2; grid-row: 1 / span 4; margin: 0; padding: 0 0 0 12px; border-top: 0; border-left: 1px solid var(--card-rule); }
  .kk-card h1 { font-size: 45px; }
  .kk-card:not(#kk-title) { padding: 11px 15px; }
  #kk-upgrade { width: min(100%, 710px); }
  #kk-upgrade-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #kk-end { width: min(100%, 680px); display: grid; grid-template-columns: .9fr 1.1fr; column-gap: 18px; }
  #kk-end h2, #kk-end-cause, #kk-end .kk-end-score-line, #kk-end-kredits-row, #kk-hof { grid-column: 1; }
  #kk-end .kk-rule { display: none; }
  #kk-end-stats { grid-column: 2; grid-row: 1 / span 3; }
  #kk-end .kk-end-actions { grid-column: 2; }
}
