/*
 * The Color Pages browser player.
 * One stylesheet shared by every game's player. Each page sets its game on
 * <html class="game-…"> and the masthead, kicker and A button follow its ink.
 */
:root {
  color-scheme: light;
  --paper: #faf6ec;
  --paper-2: #f3eddd;
  --ink: #161616;
  --ink-2: #4a4741;
  --ink-3: #6f6a60;
  --rule: #1d1d1d;
  --hair: #cfc7b4;
  --c: #00aeef;
  --m: #ec008c;
  --y: #ffe600;
  --focus: #00658a;
  --game-ink: var(--ink);
  --game-on-ink: var(--paper);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --display: "Playfair Display", Georgia, serif;
  --sans: "Libre Franklin", "Helvetica Neue", Arial, sans-serif;
  --black: "UnifrakturCook", "Old English Text MT", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.game-prism { --game-ink: var(--c); --game-on-ink: var(--ink); }
.game-inkspring { --game-ink: var(--m); --game-on-ink: #fff; }
.game-honey { --game-ink: var(--y); --game-on-ink: var(--ink); }
.game-cypher { --game-ink: var(--ink); --game-on-ink: var(--paper); }

* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh;
  background-color: var(--paper);
  background-image: radial-gradient(rgba(22, 22, 22, .045) 1px, transparent 1.2px);
  background-size: 5px 5px;
  color: var(--ink); font-family: var(--serif); font-size: 1rem; line-height: 1.5;
}
a { color: inherit; text-decoration-color: var(--m); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { background: var(--y); }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
:where(a, button, canvas):focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
.page { max-width: 1100px; margin-inline: auto; padding: 0 clamp(14px, 4vw, 40px) 32px; }

/* ---------- Masthead ---------- */
.masthead { padding-top: 10px; }
.flag {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding-bottom: 8px; font: 600 .72rem/1.3 var(--sans); letter-spacing: .04em;
}
.nameplate {
  font: 700 clamp(1.5rem, 3.4vw, 2.1rem)/1 var(--black); text-decoration: none; white-space: nowrap;
  text-shadow: -1.5px .5px 0 rgba(0, 174, 239, .85), 1.5px -.5px 0 rgba(236, 0, 140, .8), .5px 1.5px 0 rgba(255, 230, 0, .95);
}
.nameplate:hover { background: none; }
.nameplate .ink-c, .nameplate .ink-m, .nameplate .ink-y { text-shadow: 1px 1px 0 var(--ink); }
.nameplate .ink-c { color: var(--c); }
.nameplate .ink-m { color: var(--m); }
.nameplate .ink-y { color: #f6c900; }
.flag-links { display: flex; gap: 18px; }
.flag-links a { text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.flag-links .short { display: none; }
.flag-links a:hover { background: none; border-bottom-color: var(--m); }

.colorbar { display: flex; height: 8px; }
.colorbar i { flex: 1; background: var(--s); }

.headline {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 6px 24px;
  padding: 18px 0 14px; border-bottom: 3px double var(--rule);
}
.kicker {
  grid-column: 1 / -1; justify-self: start;
  font: 800 .7rem/1 var(--sans); text-transform: uppercase; letter-spacing: .14em;
  padding: .45em .65em; background: var(--game-ink); color: var(--game-on-ink);
}
h1 { font: 900 clamp(2rem, 5.2vw, 3.3rem)/1.02 var(--display); letter-spacing: -.02em; }
.deck { grid-column: 1; font-style: italic; font-size: 1.08rem; color: var(--ink-2); }
.byline {
  grid-column: 2; grid-row: 2 / span 2; align-self: end; text-align: right;
  font: 700 .68rem/1.6 var(--sans); text-transform: uppercase; letter-spacing: .1em; color: var(--ink-2);
}

/* ---------- Layout ---------- */
.game-layout {
  display: grid; grid-template-columns: max-content minmax(200px, 300px); justify-content: space-between; align-items: start;
  gap: clamp(28px, 5vw, 64px); padding-top: clamp(24px, 4vh, 40px);
}

/* The handheld stays dark so the screen reads true, framed like a plate. */
.console {
  --screen: 480px; --rim: 16px;
  width: calc(var(--screen) + 2 * var(--rim) + 2px); max-width: calc(100% - 16px);
  padding: var(--rim); border: 2px solid var(--ink); border-radius: 18px 18px 30px 18px;
  background: linear-gradient(155deg, #2c2e3d, #1d1e2b 53%, #23222f); color: #f4f3f8;
  box-shadow: 5px 5px 0 var(--c), 10px 10px 0 var(--m), 15px 15px 0 var(--y);
  margin-bottom: 15px;
}
.screen-frame { width: 100%; position: relative; line-height: 0; border-radius: 3px; outline: 4px solid #12131c; }
canvas { display: block; width: 100%; height: auto; aspect-ratio: 10 / 9; background: #0e0e24; image-rendering: pixelated; }
.screen-status {
  position: absolute; inset: 0; display: grid; align-content: center; justify-items: center; gap: 16px;
  background: var(--paper); color: var(--ink); text-align: center; padding: 16px; font: 600 .9rem/1.55 var(--sans);
}
.screen-status a { text-decoration-color: var(--m); }
#controller {
  display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; column-gap: 8px;
  padding: 17px 4px 1px; user-select: none; -webkit-user-select: none; touch-action: none;
}
#controller button {
  border: 1px solid #656477; border-radius: 8px; background: #242535; box-shadow: inset 0 1px 0 #ffffff16, 0 3px 0 #141420;
  display: grid; place-items: center; touch-action: none; padding: 0; font-family: var(--sans); color: #e3e1ed;
}
#controller button:active, #controller button.is-down, #controller button.btnPressed {
  transform: translateY(2px); filter: brightness(1.2); box-shadow: inset 0 1px 3px #0006;
}
.dpad { --key: 34px; display: grid; grid: repeat(3,var(--key)) / repeat(3,var(--key)); gap: 1px; }
.dpad::before {
  content: ""; grid-area: 2 / 2; align-self: stretch; margin: 2px;
  border: 1px solid #4d4e60; border-radius: 6px; background: #2d2e41;
}
#controller .dpad button { border-color: #555569; border-radius: 5px; color: #dbdce6; }
.dpad button span { width: 0; height: 0; border: 5px solid transparent; border-bottom: 7px solid currentColor; border-top: 0; }
#controller_up { grid-area: 1 / 2; }
#controller_left { grid-area: 2 / 1; }
#controller_left span { rotate: -90deg; }
#controller_right { grid-area: 2 / 3; }
#controller_right span { rotate: 90deg; }
#controller_down { grid-area: 3 / 2; }
#controller_down span { rotate: 180deg; }
.system-keys { display: flex; gap: 6px; align-self: end; justify-content: center; padding-bottom: 7px; }
#controller .system-keys button {
  min-height: 34px; padding: 0 9px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; border-radius: 15px;
}
.action-keys { display: flex; align-items: center; gap: 9px; padding: 0 2px 12px; }
#controller .action-keys button {
  font: 800 20px/1 var(--sans); width: 47px; height: 47px; border-radius: 50%; color: var(--ink);
}
#controller #controller_a { background: var(--game-ink); border-color: #fff8; color: var(--game-on-ink); align-self: start; }
#controller #controller_b { background: var(--paper); border-color: #fff; margin-top: 24px; }
.game-cypher #controller #controller_a { background: #e0a052; color: var(--ink); }

/* ---------- Guide ---------- */
.guide { padding-top: 4px; }
.guide h2 {
  font: 800 .74rem/1.3 var(--sans); text-transform: uppercase; letter-spacing: .16em;
  padding-bottom: .7em; border-bottom: 2px solid var(--ink);
}
.guide p { color: var(--ink-2); font-size: .95rem; line-height: 1.55; margin-top: 14px; }
.guide .rules { color: var(--ink); font-size: 1.08rem; line-height: 1.45; }
.guide .rules::first-letter {
  font: 900 2.7em/.8 var(--display); float: left; padding: .06em .08em 0 0;
  text-shadow: 2px 2px 0 var(--game-ink);
}
.guide strong { color: var(--ink); font-weight: 600; }
.guide h3 {
  margin-top: 26px; padding-top: 10px; border-top: 1px solid var(--ink);
  font: 800 .7rem/1.4 var(--sans); text-transform: uppercase; letter-spacing: .14em;
}
.key-list { margin: 4px 0 0; }
.key-list > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 36px; border-bottom: 1px dotted var(--ink-3); }
dt { font-size: .9rem; color: var(--ink-2); }
dd { margin: 0; text-align: right; font-size: .85rem; }
kbd {
  display: inline-block; padding: .05em .45em; line-height: 1.5; font: 600 12px/1.5 var(--sans);
  border: 1px solid var(--ink); border-radius: 4px; background: #fffdf7; color: var(--ink); white-space: nowrap;
  box-shadow: 0 2px 0 var(--ink);
}
.guide .note { font-style: italic; }
.guide .save-message, .noscript { color: #a4161a; font-family: var(--sans); font-size: .85rem; }
.guide .guide-link { font: 600 .8rem/1.4 var(--sans); }
.clues { padding: 0; margin: 16px 0 0; list-style: none; }
.clues li { display: grid; grid-template-columns: 14px 74px auto; align-items: center; gap: 8px; color: var(--ink-2); font-size: .85rem; line-height: 1.8; }
.clues i { width: 12px; height: 12px; border-radius: 2px; border: 1px solid var(--ink); }
.clues .correct { background: #6fd3a8; }
.clues .misplaced { background: #f5c04a; }
.clues .absent { background: #66728a; }

/* ---------- Colophon ---------- */
.colophon {
  margin-top: 40px; padding-top: 16px; border-top: 3px double var(--rule);
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px;
  font: 500 .72rem/1.5 var(--sans); color: var(--ink-3);
}
.colophon p { max-width: 60ch; }

/* ---------- Responsive ---------- */
@media (min-width: 1100px) and (min-height: 1000px) {
  .page { max-width: 1220px; }
  .console { --screen: 640px; }
}
@media (max-width: 830px) {
  .game-layout { gap: 28px; grid-template-columns: minmax(0,max-content) minmax(175px,230px); }
}
@media (min-width: 701px) and (max-width: 810px) {
  .console { --screen: 320px; }
  .game-layout { justify-content: space-evenly; }
}
@media (max-width: 700px) {
  .page { max-width: 560px; padding-inline: 14px; }
  .flag-links .wide { display: none; }
  .flag-links { gap: 2px 12px; flex-wrap: wrap; justify-content: flex-end; }
  .flag-links .long { display: none; }
  .flag-links .short { display: inline; }
  .headline { grid-template-columns: 1fr; padding: 14px 0 12px; }
  .byline { grid-column: 1; grid-row: auto; text-align: left; }
  .deck { font-size: 1rem; }
  .game-layout { display: flex; flex-direction: column; gap: 22px; align-items: center; padding-top: 20px; }
  .console { --screen: 320px; --rim: 11px; box-shadow: 4px 4px 0 var(--c), 8px 8px 0 var(--m), 12px 12px 0 var(--y); }
  .guide { width: 100%; max-width: 360px; }
  .guide h3 { margin-top: 20px; }
  .guide p { margin-top: 10px; }
  #controller { padding: 14px 0 2px; column-gap: 4px; }
  .action-keys { gap: 5px; padding-right: 0; }
  #controller .action-keys button { width: 43px; height: 43px; }
  .system-keys { gap: 4px; }
  #controller .system-keys button { padding-inline: 6px; min-height: 36px; }
  .dpad { --key: 31px; }
}
@media (pointer: coarse) and (min-width: 366px) and (orientation: portrait) {
  .dpad { --key: 40px; }
  #controller .action-keys button { width: 45px; height: 45px; }
  #controller .system-keys button { min-height: 42px; }
}
@media (max-width: 700px) and (orientation: portrait), (max-width: 349px) {
  .system-keys { flex-direction: column; align-self: center; align-items: center; padding-bottom: 0; }
  #controller .system-keys button { min-width: 55px; }
}
/* A phone on its side: keep the screen big and the controls at its edges. */
@media (orientation: landscape) and (max-height: 520px) and (min-width: 550px) {
  .page { max-width: 900px; padding: 0 10px 24px; }
  .masthead { display: flex; align-items: center; gap: 14px; }
  .flag { flex: 1; padding-bottom: 4px; }
  .colorbar, .deck, .byline, .kicker { display: none; }
  .headline { padding: 4px 0; border: 0; }
  h1 { font-size: 1.2rem; }
  .masthead { border-bottom: 3px double var(--rule); }
  .game-layout { display: flex; flex-direction: column; align-items: center; padding-top: 9px; gap: 20px; }
  .console { position: relative; width: 100%; max-width: none; padding: 7px 0; border-radius: 13px; box-shadow: 4px 4px 0 var(--c), 8px 8px 0 var(--m); }
  .screen-frame { width: min(320px, calc((100svh - 70px) * 10 / 9), 56%); margin: auto; }
  #controller { position: absolute; inset: 0; pointer-events: none; display: block; padding: 0; }
  #controller > div { position: absolute; pointer-events: auto; }
  .dpad { --key: clamp(30px, 5vw, 40px); left: 2%; top: 50%; transform: translateY(-50%); }
  .action-keys { right: 2%; top: 38%; transform: translateY(-50%); }
  .system-keys { right: 2%; top: 73%; }
  .guide { width: 100%; max-width: 600px; }
}
@media (prefers-reduced-motion: reduce) {
  #controller button:active, #controller button.is-down { transform: none; }
}
