:root {
  --lcd: #b5c1af;
  --lcd-edge: #9aa597;
  --ink: #202523;
  --ghost: 0.15;
  --body: #2b2f2d;
  --body-hi: #3a3f3c;
  --btn: #d9492f;
  --btn-dark: #a5321f;
  --label: #e9e4d6;
  --panel: clamp(88px, 17vw, 210px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--body);
  color: var(--label);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#device {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding:
    max(6px, env(safe-area-inset-top))
    max(6px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom))
    max(6px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 40%, var(--body-hi), var(--body) 70%);
}

/* ---------- LCD screen ---------- */
#screen {
  position: relative;
  aspect-ratio: 1200 / 896;
  height: min(
    calc(100dvh - max(12px, env(safe-area-inset-top) + env(safe-area-inset-bottom))),
    calc((100vw - 2 * var(--panel) - env(safe-area-inset-left) - env(safe-area-inset-right)) * 896 / 1200)
  );
  background: var(--lcd);
  border-radius: 1.6% / 2.1%;
  box-shadow:
    inset 0 0 0 2px var(--lcd-edge),
    inset 0 6px 18px rgba(0, 0, 0, 0.18),
    0 0 0 6px #151816,
    0 0 0 8px #444a46;
  overflow: hidden;
  cursor: pointer;
}

#lcd { display: block; width: 100%; height: 100%; }

/* LCD segments: every sprite is always drawn; "off" ones are faint ghosts */
#lcd .k  { fill: var(--ink); }
#lcd .b  { fill: var(--lcd); }
#lcd .ks { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; }
#lcd .bs { fill: none; stroke: var(--lcd); stroke-linecap: round; stroke-linejoin: round; }
#lcd .kb { fill: var(--lcd); stroke: var(--ink); stroke-linejoin: round; stroke-linecap: round; }
#lcd .txt { fill: var(--ink); font: 800 34px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: 1px; }
#lcd .cap { fill: var(--ink); font: 700 20px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: 2px; opacity: 0.55; }
#lcd .sp, #lcd .sg { opacity: var(--ghost); }
#lcd .sp.on, #lcd .sg.on { opacity: 1; }

#hint {
  position: absolute;
  left: 50%;
  bottom: 3.5%;
  transform: translateX(-50%);
  padding: 0.35em 0.9em;
  border-radius: 999px;
  background: rgba(29, 34, 31, 0.82);
  color: var(--lcd);
  font-size: clamp(11px, 2.4vh, 16px);
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.3s;
}
#hint.hidden { opacity: 0; }

/* ---------- side panels ---------- */
.panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  gap: 4px;
  min-width: var(--panel);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: none;
}

.small {
  min-width: min(84%, 120px);
  height: clamp(28px, 9vh, 40px);
  padding: 0 12px;
  border-radius: 999px;
  background: #4b524e;
  box-shadow: 0 3px 0 #1a1d1b, inset 0 1px 0 rgba(255,255,255,0.12);
  font-weight: 800;
  font-size: clamp(11px, 3.2vh, 15px);
  letter-spacing: 1px;
}
.small.active { background: #6b746f; }
.small:active, .small.pressed { transform: translateY(2px); box-shadow: 0 1px 0 #1a1d1b; }

.big {
  position: relative;
  width: min(30vh, calc(var(--panel) - 20px), 150px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f06a4f, var(--btn) 55%, var(--btn-dark));
  box-shadow: 0 6px 0 #5e1c11, 0 8px 14px rgba(0,0,0,0.45), inset 0 2px 0 rgba(255,255,255,0.25);
  transition: transform 0.04s;
}
.big.pressed { transform: translateY(5px); box-shadow: 0 1px 0 #5e1c11, 0 2px 6px rgba(0,0,0,0.4), inset 0 2px 0 rgba(255,255,255,0.2); }
.big svg { position: absolute; inset: 28%; width: 44%; height: 44%; fill: rgba(0,0,0,0.28); }

.row { display: flex; gap: 8px; }
.icon {
  width: clamp(30px, 10vh, 42px);
  height: clamp(30px, 10vh, 42px);
  border-radius: 50%;
  background: #4b524e;
  box-shadow: 0 3px 0 #1a1d1b;
  display: grid;
  place-items: center;
}
.icon svg { width: 55%; height: 55%; fill: var(--label); }
.icon.off { opacity: 0.45; }
.icon:active { transform: translateY(2px); box-shadow: 0 1px 0 #1a1d1b; }

/* ---------- portrait warning ---------- */
#rotate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background: var(--body);
  font-size: 18px;
  font-weight: 700;
}
#rotate svg { width: 96px; height: 96px; fill: var(--label); animation: tilt 2.2s ease-in-out infinite; }
@keyframes tilt { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }

@media (orientation: portrait) and (max-width: 900px) {
  #rotate { display: flex; }
}

#lcd .sg { opacity: 0.22; }
#lcd .sg.on { opacity: 1; }
#lcd image { image-rendering: auto; }
