:root {
  --ink: #1b1424; --paper: #f4eee0; --night: #1c1838; --gold: #f8d848; --mint: #7ef0a0;
  --mono: Menlo, Monaco, Consolas, "DejaVu Sans Mono", monospace;
}
html, body { margin: 0; height: 100%; background: #0c0a18; overflow: hidden; touch-action: none; }
#screen { display: block; image-rendering: pixelated; image-rendering: crisp-edges; outline: none; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; color: var(--gold); font: 700 18px var(--mono); }

/* Sheets: pixel panels over the game for places, conversations, the collection and help. */
.sheet { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 3vh 3vw; background: rgba(10, 8, 26, .55); }
.sheet[hidden] { display: none; }
.sheet-box {
  --cat: var(--gold);
  position: relative; width: min(620px, 100%); max-height: 92vh; overflow: auto; box-sizing: border-box;
  padding: 22px 24px 16px; color: var(--paper); background: var(--night);
  font: 500 15px/1.5 var(--mono);
  border: 4px solid var(--paper);
  box-shadow: 0 0 0 4px var(--ink), inset 0 0 0 3px var(--night), inset 0 0 0 5px rgba(244, 238, 224, .25), 8px 10px 0 4px rgba(0, 0, 0, .45);
  animation: pop .22s steps(4);
}
#card .sheet-box { border-left: 14px solid var(--cat); }
@keyframes pop { from { transform: scale(.94) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet header { display: flex; gap: 18px; align-items: center; margin-bottom: 12px; }
.c-sign canvas, .t-face canvas { display: block; image-rendering: pixelated; }
.t-face { background: #2a2450; padding: 6px 10px 0; border: 3px solid var(--ink); box-shadow: inset 0 0 0 2px #4a4480; }
.c-kind { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--cat); }
.sheet h2 { margin: 2px 0 4px; font-size: clamp(20px, 3.2vw, 28px); line-height: 1.15; color: #fff; }
.c-addr { margin: 0; color: #b8b4d8; }
.c-desc { margin: 4px 0 12px; font-size: 16px; }
.c-desc:empty { display: none; }
.c-quip { margin: 2px 0 10px; font-size: 16px; font-style: italic; color: var(--gold); }
.c-quip:empty { display: none; }
.c-quip::before { content: '“'; } .c-quip::after { content: '”'; }
.c-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0 0 14px; }
.c-facts:empty { display: none; }
.c-facts dt { color: var(--gold); font-weight: 800; }
.c-facts dd { margin: 0; }
.c-links { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.c-links a {
  color: var(--ink); background: var(--gold); text-decoration: none; font-weight: 800; padding: 6px 12px;
  border: 3px solid var(--ink); box-shadow: inset -3px -3px 0 #c8a020, inset 3px 3px 0 #fff2a0;
}
.c-links a:hover { background: #ffe470; }
.c-links .snack { font: 800 14px var(--mono); color: #fff; background: #2a8a4a; border: 3px solid var(--ink); box-shadow: inset -3px -3px 0 #1a6a32, inset 3px 3px 0 #6ad08a; padding: 6px 12px; cursor: pointer; }
.c-links .snack:disabled { background: #4a4a5a; box-shadow: none; color: #c8c4d8; cursor: default; }
.sheet footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 6px; font-size: 13px; color: #b8b4d8; }
.sheet footer button, .talk-box form button {
  font: 800 13px var(--mono); color: #fff; background: #3a3480; border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px #6a64b0; padding: 7px 12px; cursor: pointer;
}
.sheet footer button:hover, .talk-box form button:hover { background: #4a44a0; }
.sheet button:focus-visible, .sheet a:focus-visible, .sheet input:focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; }
.credit { margin: 10px 0 0; font-size: 11px; opacity: .55; }
.c-count { color: var(--mint); font-weight: 700; }

/* Conversation */
.t-who { font-size: 20px !important; }
.t-log { display: flex; flex-direction: column; gap: 8px; max-height: 42vh; overflow: auto; padding: 4px 2px 10px; }
.t-log p { margin: 0; padding: 8px 12px; max-width: 85%; border: 3px solid var(--ink); }
.t-log .npc { align-self: flex-start; background: var(--paper); color: var(--ink); box-shadow: 3px 3px 0 rgba(0, 0, 0, .3); }
.t-log .me { align-self: flex-end; background: #2a8a7a; color: #fff; box-shadow: 3px 3px 0 rgba(0, 0, 0, .3); }
.t-log .old { opacity: .55; box-shadow: none; }
.t-log .wait { animation: blink 0.6s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.talk-box form { display: flex; gap: 8px; margin-top: 6px; }
.talk-box input { flex: 1; min-width: 0; font: 600 15px var(--mono); color: #fff; background: #0c0a18; border: 3px solid #6a64b0; padding: 8px 10px; border-radius: 0; outline: none; }
.talk-box input:focus { border-color: var(--gold); }
.talk-box input:disabled { opacity: .5; }

/* Collection */
.book-box { width: min(760px, 100%); }
.b-pct { margin: 0; color: var(--mint); font-weight: 700; }
.b-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.b-tabs button { --cat: var(--gold); font: 700 12px var(--mono); color: var(--paper); background: #2a2450; border: 3px solid var(--ink); border-bottom-color: var(--cat); padding: 5px 9px; cursor: pointer; }
.b-tabs button.on { background: var(--cat); color: var(--ink); }
.b-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; max-height: 56vh; overflow: auto; }
.b-list li button { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; font: 500 12px var(--mono); color: #c8c4e8; background: #24204a; border: 3px solid var(--ink); border-left: 8px solid var(--cat); padding: 7px 9px; cursor: pointer; }
.b-list li button:hover { background: #312c64; }
.b-list li b { color: #fff; font-size: 14px; }
.b-list .empty { grid-column: 1 / -1; padding: 20px; text-align: center; color: #b8b4d8; }

/* Help */
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.keys dt { color: var(--gold); font-weight: 800; }
.keys dd { margin: 0; }

/* Controls legend, bottom right while playing (placed by placeKeys in main.js) */
#keys { position: fixed; right: 8px; bottom: 12px; z-index: 4; max-width: calc(100vw - 16px); box-sizing: border-box;
  color: var(--paper); background: rgba(28, 24, 56, .92); font: 500 13px/1.3 var(--mono);
  border: 3px solid var(--paper); box-shadow: 0 0 0 3px var(--ink), 5px 6px 0 3px rgba(0, 0, 0, .4); }
#keys[hidden] { display: none; }
#keys { transition: opacity .2s; }
#keys.dim:not(:hover):not(:focus-within) { opacity: .3; }
.k-toggle { display: flex; align-items: center; gap: 8px; width: 100%; padding: 5px 8px; font: 800 12px var(--mono);
  letter-spacing: .06em; text-transform: uppercase; color: var(--gold); background: #2a2450; border: 0; cursor: pointer; text-align: left; }
.k-toggle:hover { background: #3a3480; }
.k-toggle:focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; }
.k-toggle span:first-child { flex: 1; }
.k-state::before { content: '▾'; }
#keys.min .k-state::before { content: '▸'; }
#keys.min .k-list { display: none; }
.k-list { display: grid; grid-template-columns: auto auto; gap: 4px 14px; margin: 0; padding: 6px 8px 8px; }
.k-list div { display: flex; align-items: center; gap: 6px; }
.k-list dt { margin: 0; color: #c8c4e8; }
.k-list dd { margin: 0; }
#keys kbd { display: inline-block; min-width: 1.1em; padding: 0 4px; text-align: center; font: 800 12px/1.45 var(--mono);
  color: var(--gold); background: #4a4278; border: 2px solid var(--ink); box-shadow: inset 0 1px 0 #6a62a8; text-transform: none; letter-spacing: 0; }
.k-toggle kbd { color: var(--paper); }
@media (max-width: 900px), (max-height: 620px) {
  #keys { font-size: 12px; }
  #keys kbd { font-size: 11px; }
  #keys .alt { display: none; }
  .k-list { gap: 2px 10px; }
}

/* Touch pad */
#pad { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 0 16px calc(16px + env(safe-area-inset-bottom)); pointer-events: none; z-index: 5; }
#pad[hidden] { display: none; }
#pad button { pointer-events: auto; font: 700 18px var(--mono); color: #fff; background: rgba(28, 24, 56, .7); border: 3px solid var(--paper); border-radius: 0; width: 52px; height: 52px; padding: 0; user-select: none; -webkit-user-select: none; touch-action: none; }
#pad button.on { background: var(--gold); color: var(--ink); }
#pad button.small { font-size: 11px; width: 46px; height: 32px; }
.dpad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px); }
.dpad [data-k=up] { grid-area: 1 / 2; } .dpad [data-k=left] { grid-area: 2 / 1; } .dpad [data-k=right] { grid-area: 2 / 3; } .dpad [data-k=down] { grid-area: 3 / 2; }
.ab { display: grid; grid-template-columns: 52px 52px; gap: 10px; align-items: end; }
.ab [data-k=act] { transform: translateY(-26px); }
@media (max-width: 560px) { .sheet-box { padding: 16px; font-size: 14px; } .sheet header { gap: 12px; } }
