:root {
  --bg: #121214;
  --surface: #1e1e22;
  --surface-2: #2a2a30;
  --text: #f2f2f4;
  --muted: #a0a0aa;
  --accent: #4f8cff;
  --accent-press: #3b74e0;
  --ok: #3ccf7a;
  --warn: #f5b942;
  --danger: #ff6b6b;
  --radius: 14px;
  --tap: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, .button {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:active, .button:active { filter: brightness(0.85); }
button.primary, .button.primary { background: var(--accent); color: #fff; }
button.primary:active, .button.primary:active { background: var(--accent-press); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, .button:focus-visible, input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

input[type="text"], input[type="number"], input[type="url"] {
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- Home page */

.home {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(48px + var(--safe-top)) calc(20px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(20px + var(--safe-left));
}
.home main { width: 100%; max-width: 620px; }

/* Home page backdrop: layered mountain ranges along the bottom, behind all content. */
.home { position: relative; isolation: isolate; }
.scenery {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: clamp(130px, 20vw, 280px);
  z-index: -1;
  pointer-events: none;
}
.scenery svg { display: block; width: 100%; height: 100%; }
.scenery .range-far { fill: #22283a; opacity: 0.55; }
.scenery .snow { fill: #3a4158; opacity: 0.45; }
.scenery .range-mid { fill: #1d2130; opacity: 0.8; }
.scenery .range-near { fill: #181a22; }
.site-footer { position: relative; }
.home h1 { font-size: 2.2rem; line-height: 1.15; margin: 0 0 8px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { width: 1.4em; height: 1.4em; flex: none; }
.home .lede { color: var(--muted); margin: 0 0 32px; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 260px;
  padding: 32px 20px;
  border: 2px dashed var(--surface-2);
  border-radius: 20px;
  background: var(--surface);
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragging { border-color: var(--accent); background: #1d2433; }
.dropzone .hint { color: var(--muted); font-size: 0.95rem; margin: 0; }
.dropzone .sample { margin-top: 8px; }
.link-button {
  min-height: 44px;
  min-width: 0;
  padding: 0 4px;
  background: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.dropzone .button { min-height: 64px; padding: 0 32px; font-size: 1.15rem; }

.progress {
  width: 100%;
  max-width: 360px;
  height: 10px;
  border-radius: 5px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.1s; }

.error { color: var(--danger); margin: 0; }

.recent { margin-top: 40px; }
.recent h2 { font-size: 1.05rem; color: var(--muted); font-weight: 600; margin: 0 0 12px; }
/* minmax(0, 1fr) and the min-width: 0s below let rows shrink to the page width,
   so long room names get an ellipsis instead of widening the page. */
.recent ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.recent a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.recent a:active { background: var(--surface-2); }
.recent li { display: flex; gap: 8px; }
.recent li a { flex: 1; min-width: 0; }
.delete-room { flex: none; min-height: 64px; width: 64px; padding: 0; background: var(--surface); color: var(--muted); }
.delete-room.confirm { width: auto; padding: 0 16px; background: var(--danger); color: #fff; }
.recent .name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .meta { flex: none; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }

.steps { color: var(--muted); font-size: 0.95rem; margin-top: 40px; padding-left: 1.2em; }
.steps li { margin-bottom: 6px; }

/* Reserve space so the page doesn't jump when the ad loads; collapse it when
   Google has no ad to show (e.g. before AdSense approval). */
.ad-top { width: 100%; max-width: 728px; min-height: 100px; margin: 0 auto 32px; }
.ad-top:has(ins[data-ad-status="unfilled"]) { display: none; }

.site-footer {
  margin-top: auto;
  padding-top: 40px;
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 20px;
}
.site-footer .link-button { font-weight: 400; font-size: inherit; }
.site-footer a, .legal a { color: var(--accent); }

.legal { line-height: 1.6; }
.legal h2 { font-size: 1.3rem; margin: 36px 0 8px; }
.legal h3 { font-size: 1.05rem; margin: 24px 0 4px; }
.legal p, .legal li { color: #d6d6dc; }
.legal ul { padding-left: 1.3em; }
.legal li { margin-bottom: 8px; }
.legal .lede { margin-bottom: 24px; }

/* ---------------------------------------------------------------- Room page */

body.room {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  position: fixed;
  inset: 0;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  background: var(--bg);
}
#stage canvas {
  display: block;
  background: #fff;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.5);
}

/* Brief edge glow so the leader sees that a tap registered. */
.turn-flash {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 18%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease-out;
}
.turn-flash.left { left: 0; background: linear-gradient(to right, rgba(79, 140, 255, 0.35), transparent); }
.turn-flash.right { right: 0; background: linear-gradient(to left, rgba(79, 140, 255, 0.35), transparent); }
.turn-flash.edge { background: linear-gradient(to left, rgba(255, 107, 107, 0.35), transparent); }
.turn-flash.left.edge { background: linear-gradient(to right, rgba(255, 107, 107, 0.35), transparent); }
.turn-flash.show { opacity: 1; transition: none; }

.page-pill {
  position: fixed;
  right: calc(12px + var(--safe-right));
  bottom: calc(12px + var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(20, 20, 24, 0.72);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }

.menu-btn {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  background: rgba(20, 20, 24, 0.6);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 1.5rem;
  z-index: 20;
  transition: opacity 0.3s;
}
.menu-btn.dim { opacity: 0.35; }

.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: calc(12px + var(--safe-top)) calc(84px + var(--safe-right)) 12px calc(12px + var(--safe-left));
  background: rgba(20, 20, 24, 0.92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
  transform: translateY(-110%);
  transition: transform 0.2s ease-out;
}
.toolbar.open { transform: none; }
.toolbar .title {
  flex: 1 1 200px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.toolbar .title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar .title-row { display: flex; align-items: center; gap: 4px; min-width: 0; }
.rename-btn {
  flex: none;
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  background: none;
  color: var(--muted);
  font-size: 1.15rem;
}
/* "TetrisTheme.pdf · 1 viewer" rather than running the two together. */
#piece-count:not(:empty) + #viewer-count:not([hidden]):not(:empty)::before { content: '· '; }
#rename-input { width: 100%; margin-bottom: 8px; }
#rename-error { margin-bottom: 8px; }
.toolbar .title > span { color: var(--muted); font-size: 0.85rem; }
.toolbar .group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar input[type="number"] { width: 90px; text-align: center; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: middle;
}
.badge.leader { background: var(--accent); color: #fff; }
.badge.viewer { background: var(--surface-2); color: var(--text); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) calc(20px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
  background: rgba(0, 0, 0, 0.6);
}
.panel {
  width: 100%;
  max-width: 520px;
  max-height: 100%;
  overflow: auto;
  padding: 24px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  user-select: text;
  -webkit-user-select: text;
}
.panel h2 { margin: 0 0 4px; font-size: 1.4rem; }
.panel p { margin: 0 0 16px; color: var(--muted); }
.panel .qr {
  display: block;
  width: min(280px, 70vw);
  aspect-ratio: 1;
  margin: 0 auto 16px;
  padding: 10px;
  border-radius: 12px;
  background: #fff;
}
.panel .link-row { display: flex; gap: 8px; margin-bottom: 12px; }
.panel .link-row input { flex: 1; min-width: 0; font-size: 0.95rem; }
.panel .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.panel details { margin: 16px 0 8px; color: var(--muted); }
.panel details summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.panel details p { font-size: 0.9rem; }

.setlist { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.setlist li { display: flex; align-items: stretch; gap: 6px; }
.setlist .piece {
  flex: 1;
  min-width: 0;
  justify-content: flex-start;
  gap: 12px;
  min-height: 60px;
  padding: 8px 14px;
  text-align: left;
  font-weight: 400;
}
.setlist .piece[aria-current="true"] { background: #23324f; box-shadow: inset 0 0 0 2px var(--accent); }
.setlist .num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.5em; }
.setlist .info { display: flex; flex-direction: column; min-width: 0; }
.setlist .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.setlist .meta { color: var(--muted); font-size: 0.85rem; }
.setlist .tool { padding: 0; width: 48px; min-width: 48px; font-size: 1.1rem; }
.setlist .tool.confirm { width: auto; padding: 0 12px; background: var(--danger); color: #fff; font-size: 0.95rem; }
.setlist div.piece { display: flex; align-items: center; border-radius: var(--radius); background: var(--surface-2); }
.add-confirm { padding: 12px 0; }
.add-confirm strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#add-area { margin-bottom: 8px; }
#add-area .progress { max-width: none; margin: 12px 0; }

.center-message {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
}
.center-message p { margin: 0; color: var(--muted); max-width: 460px; }
.center-message h2 { margin: 0; }

.hint-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  pointer-events: none;
  transition: opacity 0.6s;
}
.hint-overlay > div {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
  background: rgba(79, 140, 255, 0.18);
}
.hint-overlay > div + div { border-left: 2px dashed rgba(255, 255, 255, 0.5); }
.hint-overlay.fade { opacity: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 40;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
