/* Twisty Cube — No. 109
 * A lit object on a dark stage. Self-contained. */

:root {
  --bg: #0b0b10;
  --ink: #f2efe8;
  --jade: #3ebf95;
  --coral: #ee4f4b;
  --line: rgba(242, 239, 232, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* a soft pool of light under the cube, so it sits on a stage rather than in a void */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(78% 62% at 50% 46%, rgba(120, 132, 176, 0.15) 0%, rgba(11, 11, 16, 0) 70%);
}

/* ------------------------------------------------------------------ frame */

.frame { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
.frame__corner {
  position: absolute;
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  color: rgba(242, 239, 232, 0.26);
}
.frame__corner--tl { top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); }
/* the sound toggle owns the top-right corner, so the toy name stops short of it */
.frame__corner--tr { top: max(14px, env(safe-area-inset-top)); right: calc(max(16px, env(safe-area-inset-right)) + 44px); }
.frame__corner--bl { bottom: max(14px, env(safe-area-inset-bottom)); left: max(16px, env(safe-area-inset-left)); pointer-events: auto; }
.frame__corner--bl a { color: inherit; text-decoration: none; transition: color 0.18s ease; }
.frame__corner--bl a:hover { color: var(--jade); }
.frame__corner--bl a:focus-visible { outline: 2px solid var(--jade); outline-offset: 3px; }

/* -------------------------------------------------------------------- HUD */

.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  gap: 26px;
  justify-content: center;
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
.hud[hidden] { display: none; }
.hud__cell { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hud__k { font-size: 8.5px; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(242, 239, 232, 0.38); }
.hud__cell span:last-child { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.05; }
.hud__time { color: var(--ink); }
.hud__best { color: rgba(242, 239, 232, 0.46); font-size: 15px !important; }

.status {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 54px);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  z-index: 5;
  pointer-events: none;
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(242, 239, 232, 0.32);
  white-space: nowrap;
}

/* ------------------------------------------------------------ sound button */

.sound-btn {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 7;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: rgba(18, 18, 26, 0.74);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: rgba(242, 239, 232, 0.8);
  font-size: 14px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: color 0.18s ease, border-color 0.18s ease;
}
.sound-btn:hover { color: var(--jade); border-color: var(--jade); }
.sound-btn:focus-visible { outline: 2px solid var(--jade); outline-offset: 3px; }
.sound-btn[aria-pressed="false"] { color: rgba(242, 239, 232, 0.28); }

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

.controls {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 14px);
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 12px;
}

.size {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(20, 20, 28, 0.82);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.size__btn {
  appearance: none;
  border: none;
  background: transparent;
  color: rgba(242, 239, 232, 0.52);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.16s ease, background 0.16s ease;
}
.size__btn:hover { color: var(--ink); }
.size__btn:focus-visible { outline: 2px solid var(--jade); outline-offset: 2px; }
.size__btn.is-on { color: #06201a; background: var(--jade); }

.scramble-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(20, 20, 28, 0.82);
  color: rgba(242, 239, 232, 0.86);
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 11px 18px;
  border-radius: 999px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: color 0.16s ease, border-color 0.16s ease;
}
.scramble-btn:hover { color: var(--ink); border-color: rgba(242, 239, 232, 0.4); }
.scramble-btn:focus-visible { outline: 2px solid var(--jade); outline-offset: 3px; }

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

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(120% 100% at 50% 44%, rgba(24, 34, 40, 0.32) 0%, rgba(6, 6, 11, 0.78) 76%);
  -webkit-backdrop-filter: blur(1.5px);
  backdrop-filter: blur(1.5px);
  animation: ovIn 0.35s ease both;
}
.overlay[hidden] { display: none; }
@keyframes ovIn { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 26px 26px 24px;
  text-align: center;
  background: linear-gradient(170deg, rgba(30, 40, 46, 0.88) 0%, rgba(7, 8, 13, 0.93) 100%);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(62, 191, 149, 0.24);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(220, 255, 245, 0.1);
  color: var(--ink);
}
.panel__eyebrow {
  margin: 0 0 8px;
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--jade);
}
.panel__title {
  margin: 0 0 12px;
  font-size: clamp(32px, 7.4vw, 46px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-shadow: 0 0 44px rgba(62, 191, 149, 0.32);
}
.panel__text { margin: 0 0 20px; font-size: 14.5px; line-height: 1.6; color: rgba(242, 239, 232, 0.74); }
.panel__text b { color: var(--ink); font-weight: 700; }
.panel__keys {
  margin: 14px 0 0;
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(242, 239, 232, 0.34);
  line-height: 1.9;
}

.play-btn {
  display: inline-block;
  padding: 13px 34px;
  font-size: 14.5px;
  font-weight: 800;
  font-family: inherit;
  color: #06201a;
  background: linear-gradient(180deg, #8ff0cf 0%, #3ebf95 56%, #1e8e6c 100%);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(30, 142, 108, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.14s ease, box-shadow 0.18s ease, filter 0.18s ease;
}
.play-btn:hover { transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 14px 34px rgba(30, 142, 108, 0.54); }
.play-btn:active { transform: translateY(1px); }
.play-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

/* -------------------------------------------------- shared-badge docking
 * The cube is centred and the controls own the bottom strip, so the shared
 * badges dock bottom-right clear of both. */
.opt-tipjar.opt-tipjar { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); transform: none; }
.opt-fs.opt-fs { top: auto; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 54px); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge { animation: none; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 560px) {
  .panel { padding: 22px 18px 20px; border-radius: 15px; }
  .hud { gap: 18px; }
  .hud__cell span:last-child { font-size: 17px; }
  /* the score row runs the full width of a phone; the toy name is the
     less useful of the two labels sharing that line */
  .frame__corner--tr { display: none; }
  .controls { gap: 8px; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 52px); }
  .size__btn { padding: 8px 10px; font-size: 10.5px; }
  .scramble-btn { padding: 10px 14px; font-size: 10.5px; }
}
@media (max-height: 560px) {
  .panel { padding: 16px 18px 16px; }
  .panel__title { font-size: clamp(22px, 5vh, 30px); margin-bottom: 6px; }
  .panel__text { font-size: 12.5px; margin-bottom: 12px; }
  .panel__keys { display: none; }
  .status { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay { animation: none; }
  .play-btn, .sound-btn, .size__btn, .scramble-btn { transition: none; }
}
