/* Old School Games — shared design system. Mobile only, touch first. */

:root {
  --bg: #f4f5fa;
  --bg-deep: #e8eaf3;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --ink: #14161d;
  --ink-2: #4a5060;
  --muted: #878ea0;
  --line: #e3e6ef;

  --accent: #4f46e5;
  --accent-soft: #eceafd;
  --amber: #f59e0b;
  --amber-soft: #fef3d6;
  --good: #16a34a;
  --good-soft: #dcf5e6;
  --bad: #ef4444;
  --bad-soft: #fde5e5;
  --pink: #ec4899;
  --cyan: #06b6d4;

  --r-sm: 10px;
  --r: 16px;
  --r-lg: 24px;
  --r-full: 999px;

  --shadow: 0 1px 2px rgba(20, 22, 29, .06), 0 6px 20px rgba(20, 22, 29, .08);
  --shadow-sm: 0 1px 2px rgba(20, 22, 29, .08);
  --shadow-press: inset 0 2px 6px rgba(20, 22, 29, .14);

  --tap: 56px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --header-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
}

body.osg-scroll {
  position: relative;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- header ---------- */

.osg-header {
  position: sticky;
  top: 0;
  /* Above the overlays: a game that opens with a start card would otherwise bury
     its own back, info and sound buttons behind it. */
  z-index: 66;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--header-h) + var(--safe-t));
  padding: var(--safe-t) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}

.osg-header .osg-title {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.osg-iconbtn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease;
}

.osg-iconbtn:active { transform: scale(.9); background: var(--line); }
.osg-iconbtn[aria-pressed="false"] { color: var(--muted); }
.osg-iconbtn svg { width: 20px; height: 20px; display: block; }

/* ---------- score strip ---------- */

.osg-scores {
  display: flex;
  gap: 8px;
  padding: 10px calc(12px + var(--safe-r)) 10px calc(12px + var(--safe-l));
}

.osg-stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 8px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.osg-stat .k {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.osg-stat .v {
  display: block;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.osg-stat.is-hot .v { color: var(--accent); }

/* ---------- stage ---------- */

.osg-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
}

.osg-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

canvas.osg-canvas {
  display: block;
  touch-action: none;
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* ---------- controls ---------- */

.osg-controls {
  padding: 12px calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.osg-btn {
  min-height: var(--tap);
  padding: 0 22px;
  border: 0;
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .01em;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, filter .15s ease;
}

.osg-btn:active { transform: scale(.96); filter: brightness(.94); }
.osg-btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.osg-btn.soft { background: var(--accent-soft); color: var(--accent); }
.osg-btn.danger { background: var(--bad); }
.osg-btn.wide { width: 100%; }
.osg-btn[disabled] { opacity: .45; pointer-events: none; }

/* d-pad / action pad for games that need discrete direction taps as a fallback */

.osg-pad {
  display: grid;
  grid-template-columns: repeat(3, var(--tap));
  grid-template-rows: repeat(3, var(--tap));
  gap: 8px;
  justify-content: center;
}

.osg-pad button {
  border: 0;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  color: var(--ink-2);
  font-size: 22px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.osg-pad button:active { background: var(--accent-soft); color: var(--accent); transform: scale(.94); }
.osg-pad .sp { visibility: hidden; }

/* ---------- hint ---------- */

.osg-hint {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 16px 0;
  line-height: 1.4;
}

/* ---------- overlay ---------- */

.osg-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(20, 22, 29, .42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.osg-overlay.show { opacity: 1; pointer-events: auto; }

.osg-card {
  width: min(340px, 100%);
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 26px 22px 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(20, 22, 29, .28);
  transform: translateY(8px) scale(.98);
  transition: transform .2s cubic-bezier(.2, .8, .3, 1);
}

.osg-overlay.show .osg-card { transform: none; }

.osg-card .emoji { font-size: 40px; line-height: 1; }
.osg-card h2 { margin: 10px 0 6px; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.osg-card p { margin: 0 0 18px; color: var(--ink-2); font-size: 15px; line-height: 1.5; }
.osg-card .osg-btn + .osg-btn { margin-top: 10px; }
.osg-card .actions { display: flex; flex-direction: column; gap: 10px; }

/* ---------- how to play ---------- */

.osg-help {
  position: fixed;
  inset: 0;
  z-index: 65;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 22, 29, .42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.osg-help.show { opacity: 1; pointer-events: auto; }

.osg-help-card {
  width: min(520px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 18px 20px calc(24px + var(--safe-b));
  box-shadow: 0 -10px 50px rgba(20, 22, 29, .28);
  transform: translateY(14px);
  transition: transform .22s cubic-bezier(.2, .8, .3, 1);
}

.osg-help.show .osg-help-card { transform: none; }

.osg-help-head {
  position: sticky;
  top: -18px;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -18px -20px 10px;
  padding: 18px 20px 10px;
  background: var(--surface);
}
.osg-help-head h2 {
  flex: 1;
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.02em;
}
.osg-help-head .osg-iconbtn { font-size: 24px; }

.osg-help .lead {
  margin: 0 0 14px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-2);
}

.osg-help-players {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: var(--r);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
}

.osg-help h3 {
  margin: 16px 0 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.osg-help-rows { display: flex; flex-direction: column; gap: 8px; }
.osg-help-rows .row {
  display: flex;
  gap: 12px;
  align-items: baseline;
  font-size: 14px;
  line-height: 1.45;
}
.osg-help-rows .row b {
  flex: 0 0 108px;
  color: var(--accent);
  font-weight: 700;
}
.osg-help-rows .row span { flex: 1; color: var(--ink-2); }

.osg-help ul { margin: 0; padding-left: 20px; }
.osg-help li {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.osg-help .tip {
  margin: 16px 0 0;
  padding: 10px 14px;
  border-radius: var(--r);
  background: var(--amber-soft);
  color: #7a4a06;
  font-size: 13px;
  line-height: 1.5;
  font-weight: 600;
}

/* ---------- toast ---------- */

.osg-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 10px);
  z-index: 70;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--r-full);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}

.osg-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- utility ---------- */

.osg-row { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.osg-mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

@keyframes osg-pop { 0% { transform: scale(.82); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes osg-shake { 10%, 90% { transform: translateX(-2px); } 30%, 70% { transform: translateX(4px); } 50% { transform: translateX(-4px); } }
@keyframes osg-fadeup { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.pop { animation: osg-pop .22s ease; }
.shake { animation: osg-shake .34s ease; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
