:root {
  --bg: #AAABAC;
  --ink: #1F1E1C;
  --muted: #3D3A36;
  --paper: #F4F3F0;
  --glass: rgba(255, 255, 255, .45);
  --line: rgba(31, 30, 28, .14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#nogl {
  position: fixed;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-size: 15px;
}

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

.ui {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(28px, env(safe-area-inset-top)) max(32px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(32px, env(safe-area-inset-left));
  pointer-events: none;
}
.ui button { pointer-events: auto; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: .06em; }

.modes {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.modes button {
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.modes button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 600; }

.right { display: flex; align-items: center; gap: 20px; }
.tools { display: flex; gap: 8px; }

.count { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.count b { margin: 0 2px; font-size: 22px; font-weight: 600; color: var(--ink); }

.icon, .pill {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.icon { width: 44px; padding: 0; }
.pill { padding: 0 18px; }
.icon[aria-pressed="true"] .off, .icon[aria-pressed="false"] .on { display: none; }

button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.timer {
  width: min(100%, 1180px);
  align-self: center;
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.timer-row { display: flex; justify-content: space-between; align-items: flex-end; }
.stat { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.stat.end { align-items: flex-end; }
.stat b { font-size: 36px; font-weight: 600; line-height: 1.05; color: var(--ink); font-variant-numeric: tabular-nums; }
.bar { height: 3px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar div { width: 100%; height: 100%; border-radius: 99px; background: var(--ink); transform-origin: left; }

/* The sheet of bubble wrap is drawn by the canvas inside this box */
.slot {
  flex: 1;
  min-height: 0;
  width: min(100%, 1180px);
  align-self: center;
  margin: 56px 0 28px;
}
.timer:not([hidden]) + .slot { margin-top: 24px; }

.hint { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- Result ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(170, 171, 172, .5);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.dialog {
  width: min(100%, 360px);
  padding: 30px 22px 22px;
  border-radius: 24px;
  background: rgba(248, 248, 246, .94);
  border: 1px solid rgba(31, 30, 28, .08);
  box-shadow: 0 30px 60px -24px rgba(0, 0, 0, .35);
  display: flex;
  flex-direction: column;
  gap: 22px;
  text-align: center;
}
.result-head { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 15px; color: var(--muted); }
#result-title { letter-spacing: .08em; }
#result-score { font-size: 88px; font-weight: 700; line-height: 1; letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; }

.badge {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(31, 30, 28, .06);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}
.badge.record { background: rgba(242, 196, 109, .3); color: #6E4700; }
.badge:not(.record) svg { display: none; }

.cells { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.cell { padding: 12px; border-radius: 14px; background: rgba(31, 30, 28, .05); display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.cell b { font-size: 22px; font-weight: 600; color: var(--ink); }
.cell small { font-size: 13px; font-weight: 400; color: var(--muted); }

.actions { display: flex; flex-direction: column; gap: 10px; }
.primary, .secondary { border-radius: 999px; font: inherit; cursor: pointer; }
.primary { min-height: 52px; border: 0; background: var(--ink); color: var(--paper); font-size: 16px; font-weight: 600; }
.secondary { min-height: 48px; border: 1px solid rgba(31, 30, 28, .2); background: transparent; color: var(--ink); font-size: 15px; font-weight: 500; }

/* ---------- Phone ---------- */

@media (max-width: 640px) {
  .ui { padding: max(16px, env(safe-area-inset-top)) max(11px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(11px, env(safe-area-inset-left)); }
  .top { gap: 12px; padding: 0 7px; }
  .brand h1 { font-size: 19px; }
  /* keep the header on one row: short title and bare count, still read out by screen readers */
  .pinch, .count-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .modes { order: 3; width: 100%; }
  .modes button { flex: 1; }
  .right { gap: 12px; }
  .pill { width: 44px; padding: 0; }
  .pill span { display: none; }
  .timer { padding: 0 7px; margin-top: 16px; }
  .stat b { font-size: 40px; }
  .slot { margin: 16px 0 12px; }
  .timer:not([hidden]) + .slot { margin-top: 16px; }
}
