/* ── Eliza Game Library – Shared Theme ──────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Orbitron:wght@500;700;900&display=swap');

:root {
  --bg-deep: #0f0f1a;
  --bg-main: #1a1a2e;
  --bg-light: #1e2444;
  --bg-surface: #16213e;
  --bg-elevated: #1e2d50;
  --border: #2a2a4a;
  --border-glow: #3a3a6a;
  --accent: #e94560;
  --accent-dark: #c0304a;
  --accent-light: #ff6b81;
  --accent-glow: rgba(233, 69, 96, 0.25);
  --green: #00e676;
  --text: #eee;
  --text-dim: #999;
  --text-faint: #666;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Orbitron', 'Inter', sans-serif;
  --radius: 8px;
  --radius-sm: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: radial-gradient(ellipse at 50% 0%, var(--bg-light) 0%, var(--bg-main) 50%, var(--bg-deep) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  font-family: var(--font-ui);
  color: var(--text);
  user-select: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */

.wrapper {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

#board {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  display: block;
  box-shadow: 0 4px 30px rgba(0,0,0,0.4), 0 0 60px rgba(233,69,96,0.04);
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 140px;
}

.box {
  background: linear-gradient(145deg, var(--bg-surface), rgba(18,28,46,0.9));
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.04);
}

.box label {
  display: block;
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-faint);
  margin-bottom: 3px;
}

.box .val {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */

button {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  border: none;
  padding: 10px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 2px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  width: 100%;
  transition: all 0.15s ease;
  box-shadow: 0 2px 10px rgba(233,69,96,0.25);
}
button:hover {
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  box-shadow: 0 4px 20px rgba(233,69,96,0.35);
  transform: translateY(-1px);
}
button:active { transform: translateY(0); }

#stopBtn {
  background: linear-gradient(135deg, #555, #333);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
#stopBtn:hover {
  background: linear-gradient(135deg, #666, #444);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

#homeBtn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  box-shadow: none;
}
#homeBtn:hover {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border-glow);
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  transform: translateY(-1px);
}

button:disabled {
  background: linear-gradient(135deg, #444, #333);
  color: #777;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.keys {
  font-size: 10px;
  color: var(--text-faint);
  line-height: 2;
}
.keys span { color: var(--text-dim); font-weight: 600; }

/* ── High-Score Box ────────────────────────────────────────────────────────── */

.box-hs {
  position: relative;
}

.reset-hs {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 16px;
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: none;
  text-transform: none;
  letter-spacing: 0;
  transition: all 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.reset-hs:hover, .reset-hs:active {
  color: var(--accent);
  background: rgba(233,69,96,0.12);
  box-shadow: none;
  transform: scale(1.1);
}

/* ── Touch Control Base ────────────────────────────────────────────────────── */

.touch-pad,
.touch-left,
.touch-right { display: none; }

.tc {
  background: linear-gradient(145deg, var(--bg-surface), rgba(18,28,46,0.9));
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 22px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.08s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.tc:active, .tc.pressed {
  background: linear-gradient(145deg, #2a3a6a, var(--bg-elevated));
  border-color: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
}
.tc.tc-label {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ── Narrow Touch (portrait phone, aspect < 3/4) ──────────────────────────── */

@media (pointer: coarse) and (max-aspect-ratio: 3/4) {
  body {
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 4px;
    gap: 4px;
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .wrapper {
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
    flex: 1 1 0%;
    min-height: 0;
  }
  .sidebar {
    width: 100%;
    max-width: 420px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    order: -1;
    flex-shrink: 0;
  }
  .sidebar .box { flex: 1 1 55px; padding: 6px 8px; }
  .sidebar .box .val { font-size: 16px; }
  .sidebar .box label { font-size: 7px; margin-bottom: 1px; }
  .sidebar button { flex: 1 1 70px; padding: 8px 4px; font-size: 9px; letter-spacing: 1px; }
  .sidebar a { flex: 1 1 70px; text-decoration: none; }
  .sidebar a button { width: 100%; }
  .keys, .next-box { display: none; }

  .touch-pad {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
    max-width: 420px;
    justify-content: center;
    flex-shrink: 0;
  }
  .touch-pad .tc {
    flex: 1 1 55px;
    height: 46px;
    max-width: 100px;
  }
}

/* ── Wide Touch (square + landscape, aspect ≥ 3/4) ────────────────────────── */

@media (pointer: coarse) and (min-aspect-ratio: 3/4) {
  body {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 4px;
    gap: 6px;
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .wrapper {
    flex: 1 1 0%;
    min-width: 0;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    align-self: stretch;
    gap: 8px;
  }
  .sidebar {
    flex-shrink: 0;
    width: 110px;
    gap: 4px;
  }
  .sidebar .box { padding: 4px 8px; }
  .sidebar .box .val { font-size: 14px; }
  .sidebar .box label { font-size: 7px; margin-bottom: 1px; }
  .sidebar button { padding: 6px 8px; font-size: 9px; }
  .sidebar a { text-decoration: none; }
  .sidebar a button { width: 100%; }
  .keys, .next-box { display: none; }

  .touch-left, .touch-right {
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    gap: 6px;
    justify-content: center;
    align-items: center;
  }
  .touch-left .tc,
  .touch-right .tc {
    width: 52px;
    height: 52px;
  }
  .touch-left .tc.tc-wide,
  .touch-right .tc.tc-wide {
    width: 110px;
    height: 44px;
  }

  .touch-pad { display: none; }

  .dpad {
    display: grid;
    grid-template-areas: ". up ." "lft . rgt" ". dwn .";
    gap: 4px;
  }
  .dpad .tc { width: 48px; height: 48px; }
  .dpad #tc-up,    .dpad .tc-up    { grid-area: up; }
  .dpad #tc-left,  .dpad .tc-left  { grid-area: lft; }
  .dpad #tc-right, .dpad .tc-right { grid-area: rgt; }
  .dpad #tc-down,  .dpad .tc-down  { grid-area: dwn; }
}

/* ── Compact sidebar for short screens ─────────────────────────────────────── */

@media (max-height: 700px) and (pointer: coarse) {
  .sidebar .box { padding: 3px 6px; }
  .sidebar .box .val { font-size: 13px; }
  .sidebar { gap: 3px; }
}
