/* ===========================================================================
 * styles.css
 * ==========================================================================*/

:root {
  --bg: #0c0c10;
  --panel: #17171d;
  --panel-2: #20212a;
  --line: #2c2d38;
  --text: #f3f3f6;
  --muted: #9aa0ac;
  --accent: #6ea8ff;
}

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

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

/* ---- Pod grid ---------------------------------------------------------- */
#pod {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  gap: 8px;
  padding: 8px;
}

/* a grid cell that holds one card */
.seat {
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

/* ---- Player card ------------------------------------------------------- */
.card {
  position: absolute;
  top: 50%;
  left: 50%;
  /* width/height/transform set by JS (size swaps for 90°/270° seats) */
  border-radius: 16px;
  background: #1b1b22;
  background: color-mix(in srgb, var(--c) 30%, #14141a);
  border: 2px solid color-mix(in srgb, var(--c) 70%, #000);
  box-shadow: 0 6px 18px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.04);
  overflow: hidden;
  transition: box-shadow .15s ease, filter .15s ease;
  container-type: size;   /* so children can size text relative to THIS card */
}
.card.lit {
  filter: brightness(1.5) saturate(1.2);
  box-shadow: 0 0 0 3px #fff, 0 0 36px 6px var(--c);
}

/* the two tap halves sit at the back of the card */
.zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 1;
  touch-action: none;
  display: flex;
  align-items: center;
  font-size: min(18cqh, 12cqw);
  font-weight: 300;
  color: rgba(255,255,255,.20);
}
/* glyphs sit on the far (outer) left/right edges of the wide card */
.zone.left  { left: 0;  justify-content: flex-start; padding-left: 4cqw; }
.zone.right { right: 0; justify-content: flex-end;   padding-right: 4cqw; }
.zone:active { background: rgba(255,255,255,.10); }
.zone .glyph { pointer-events: none; }

/* the life total floats above the zones but ignores pointer events */
.life {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-weight: 800;
  font-size: min(46cqh, 30cqw);
  line-height: 1;
  letter-spacing: -.02em;
  text-shadow: 0 2px 10px rgba(0,0,0,.5);
}
.life.low { color: #ff6b6b; }

/* player name, top centre */
.name {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  font-size: clamp(11px, 2.4vmin, 16px);
  font-weight: 600;
  color: rgba(255,255,255,.7);
  pointer-events: none;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* options (⋯) button, top-right corner */
.opts {
  position: absolute;
  top: 4px;
  right: 6px;
  z-index: 3;
  width: clamp(34px, 7.5vmin, 48px);
  height: clamp(34px, 7.5vmin, 48px);
  border: none;
  border-radius: 11px;
  background: rgba(0,0,0,.25);
  color: rgba(255,255,255,.85);
  font-size: clamp(19px, 5vmin, 27px);
  line-height: 1;
  cursor: pointer;
}
.opts:active { background: rgba(0,0,0,.45); }

/* counter chips row, bottom */
.counters {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  pointer-events: none;          /* gaps between chips fall through to the ± zones */
}
/* a counter is a coloured circle with its icon on top and the count below */
.counter-dot {
  width: clamp(30px, 11cqmin, 50px);
  height: clamp(30px, 11cqmin, 50px);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;          /* the circles themselves are tappable */
  border: 2px solid rgba(0,0,0,.4);
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.counter-dot:active { transform: scale(.92); }
.cd-icon { font-size: clamp(11px, 4cqmin, 17px); }
.cd-count { font-size: clamp(12px, 4.6cqmin, 20px); font-weight: 800; margin-top: 1px; }

/* ---- In-card overlay (counter expand OR options menu) ------------------ */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  background: rgba(8,8,11,.92);
  border-radius: 14px;
}
.overlay.show { display: block; }

/* expanded-counter view: same left/right ± interaction as life */
.ov-title {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  z-index: 2;
  text-align: center;
  font-size: clamp(12px, 6cqmin, 20px);
  font-weight: 700;
  color: var(--cc, #fff);
  pointer-events: none;
}
.ov-value {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-weight: 800;
  font-size: min(40cqh, 28cqw);
}
.ov-close {
  position: absolute;
  top: 4px;
  right: 6px;
  z-index: 3;
  width: clamp(26px, 6vmin, 38px);
  height: clamp(26px, 6vmin, 38px);
  border: none;
  border-radius: 9px;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

/* options-menu list inside the overlay */
.menu-list {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* "safe center" centers when it fits but falls back to top-aligned when the
     list overflows, so the top items stay scrollable (plain "center" hides them) */
  justify-content: safe center;
}
.menu-list .mhead {
  font-size: clamp(10px, 2.2vmin, 13px);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 2px 0;
}
.menu-list button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: clamp(13px, 2.8vmin, 16px);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.menu-list button:active { background: #2a2c38; }
.menu-list button .mi { width: 1.2em; text-align: center; }
.menu-list .danger { color: #ff8a8a; border-color: #5a2a2a; }

/* radial colour picker (shown when adding a mana / counter) */
.color-picker {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(100cqw, 100cqh);     /* a centred square, so the swatches form a true circle */
  height: min(100cqw, 100cqh);
  z-index: 2;
}
.picker-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  color: var(--text);
}
.pc-icon { font-size: clamp(18px, 9cqmin, 34px); line-height: 1; }
.pc-label { font-size: clamp(10px, 3.6cqmin, 15px); color: var(--muted); margin-top: 2px; }
.swatch {
  position: absolute;
  width: clamp(32px, 13cqmin, 56px);
  height: clamp(32px, 13cqmin, 56px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.55);
  box-shadow: 0 2px 6px rgba(0,0,0,.55);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.swatch:active { transform: translate(-50%, -50%) scale(.9); }
.swatch.used { border-color: #fff; box-shadow: 0 0 0 3px #fff, 0 2px 6px rgba(0,0,0,.55); }
.swatch.used::after { content: "✓"; color: #fff; font-weight: 800; font-size: clamp(14px, 6cqmin, 24px); text-shadow: 0 1px 3px rgba(0,0,0,.9); }

.ov-back {
  position: absolute;
  top: 4px;
  left: 6px;
  z-index: 3;
  width: clamp(26px, 6vmin, 38px);
  height: clamp(26px, 6vmin, 38px);
  border: none;
  border-radius: 9px;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.ov-back:active { background: rgba(255,255,255,.22); }

/* ---- Centre pod button + crown ----------------------------------------- */
#pod-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  width: clamp(54px, 11vmin, 84px);
  height: clamp(54px, 11vmin, 84px);
  border-radius: 50%;
  border: 2px solid var(--line);
  background: radial-gradient(circle at 35% 30%, #2b2d3a, #14141b);
  color: var(--text);
  font-size: clamp(22px, 5vmin, 34px);
  cursor: grab;
  box-shadow: 0 8px 22px rgba(0,0,0,.5);
  touch-action: none;
}
#pod-center.dragging { cursor: grabbing; z-index: 60; }
#pod-center.snapping { transition: left .25s cubic-bezier(.2,.8,.2,1), top .25s cubic-bezier(.2,.8,.2,1); }

#monarch {
  position: absolute;
  z-index: 18;
  width: clamp(34px, 7vmin, 50px);
  height: clamp(34px, 7vmin, 50px);
  margin: calc(-1 * clamp(17px, 3.5vmin, 25px)) 0 0 calc(-1 * clamp(17px, 3.5vmin, 25px));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 4.5vmin, 30px);
  background: radial-gradient(circle at 35% 30%, #ffe082, #f1a821);
  border: 2px solid #7a5200;
  box-shadow: 0 4px 12px rgba(0,0,0,.5);
  cursor: grab;
  touch-action: none;
}
#monarch.dragging { cursor: grabbing; transform: scale(1.12); z-index: 60; }
#monarch.snapping { transition: left .28s cubic-bezier(.2,.8,.2,1), top .28s cubic-bezier(.2,.8,.2,1); }

/* ---- Match timer ------------------------------------------------------- */
#match-timer {
  position: fixed;
  left: 50%;
  top: 44px;
  z-index: 30;
  display: none;
  align-items: center;
  gap: 8px;
  transform: translate(-50%, -50%) rotate(0deg);
  transform-origin: center center;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
#match-timer.show { display: flex; }
#match-timer.dragging { cursor: grabbing; z-index: 60; }
#match-timer.snapping { transition: left .25s cubic-bezier(.2,.8,.2,1), top .25s cubic-bezier(.2,.8,.2,1), transform .25s cubic-bezier(.2,.8,.2,1); }
.t-pill {
  background: rgba(18,18,24,.92);
  border: 1px solid var(--line);
  color: #fff;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
  white-space: nowrap;
}
.t-main { font-size: clamp(18px, 4vmin, 26px); padding: 7px 16px; }
.t-sec {
  display: none;
  font-size: clamp(14px, 3.2vmin, 20px);
  padding: 5px 12px;
  background: #b4541f;             /* a different colour from the main timer */
  border-color: #db7233;
}
.t-sec.show { display: block; }
.t-sec.stopped { background: #59616d; border-color: #79828f; }  /* paused look */

/* ---- Modals / popovers ------------------------------------------------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
  padding: 16px;
}
.backdrop.show { display: flex; }

.modal {
  width: min(420px, 92vw);
  max-height: 88vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.modal h2 { margin: 0 0 4px; font-size: 19px; }
.modal p  { margin: 4px 0 14px; color: var(--muted); font-size: 14px; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.seg .lbl { width: 100%; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.seg button {
  flex: 1 1 auto;
  min-width: 56px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.seg button.active { border-color: var(--accent); background: #243047; color: #fff; }
.seg button:active { background: #2a2c38; }

.menu-actions { display: flex; flex-direction: column; gap: 8px; }
.menu-actions button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.menu-actions button:active { background: #2a2c38; }
.menu-actions button .mi { font-size: 20px; width: 1.4em; text-align: center; }

.row-btns { display: flex; gap: 10px; margin-top: 6px; }
.row-btns button {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.row-btns .primary { background: var(--accent); border-color: var(--accent); color: #071226; }
.row-btns .destructive { background: #c64242; border-color: #c64242; color: #fff; }

/* dice */
.dice-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.dice-grid button {
  padding: 12px 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.dice-grid button:active { background: #2a2c38; }
#dice-result {
  margin-top: 16px;
  text-align: center;
  font-size: 64px;
  font-weight: 800;
  min-height: 70px;
  color: var(--text);
}
#dice-result small { display: block; font-size: 14px; font-weight: 600; color: var(--muted); }

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  z-index: 200;
  background: #fff;
  color: #111;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Planechase -------------------------------------------------------- */
/* When active, the pod shrinks to the left half and the panel slides in. */
body.planechase-on #pod { width: 50vw; }

#planechase {
  position: fixed;
  top: 0;
  right: 0;
  width: 50vw;
  height: 100vh;
  height: 100dvh;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: linear-gradient(180deg, #101015, #0a0a0d);
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.2,.8,.2,1), opacity .3s ease;
}
body.planechase-on #planechase {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.pc-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 9px;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.pc-close:active { background: rgba(255,255,255,.22); }
.pc-rotate {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 9px;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 19px;
  cursor: pointer;
}
.pc-rotate:active { background: rgba(255,255,255,.22); }

/* the stage holds a rotatable wrapper containing the card image (or fallback) */
#plane-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}
#plane-rot {
  position: relative;
  /* width/height/transform set by JS so it fits at any rotation */
  transition: transform .32s cubic-bezier(.2,.8,.2,1), width .2s ease, height .2s ease;
}
#plane-img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.55);
  -webkit-user-select: none;
  user-select: none;
}
#plane-rot.has-img #plane-img { display: block; }
#plane-rot.has-img .plane-card { display: none; }

.plane-card {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  background: #15151c;
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.plane-art {
  height: 34%;
  min-height: 70px;
  background: linear-gradient(135deg, var(--p1, #444), var(--p2, #111));
  box-shadow: inset 0 -30px 40px rgba(0,0,0,.5);
  position: relative;
}
.plane-art::after {           /* subtle vignette/sheen */
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 80% at 30% 20%, rgba(255,255,255,.18), transparent 60%);
}
.plane-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.plane-name { font-size: clamp(17px, 2.6vw, 24px); font-weight: 800; line-height: 1.1; }
.plane-type { font-size: clamp(12px, 1.6vw, 15px); color: var(--muted); font-style: italic; margin-bottom: 2px; }
.plane-static { font-size: clamp(13px, 1.7vw, 16px); line-height: 1.35; }
.plane-chaos {
  font-size: clamp(13px, 1.7vw, 16px);
  line-height: 1.35;
  padding-top: 8px;
  margin-top: 2px;
  border-top: 1px solid var(--line);
}
.plane-chaos .chaos-mark { color: #ff7a45; font-weight: 800; margin-right: 4px; }
.plane-foot {
  padding: 7px 14px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  text-align: center;
}

.plane-caption {
  text-align: center;
  font-size: clamp(12px, 1.6vw, 15px);
  font-weight: 600;
  color: var(--muted);
  padding: 2px 4px;
}
.plane-caption:empty { display: none; }

.pc-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.pc-btn {
  flex: 1 1 calc(50% - 4px);
  padding: 13px 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-2);
  color: var(--text);
  font-size: clamp(13px, 1.7vw, 16px);
  font-weight: 700;
  cursor: pointer;
}
.pc-btn:active { background: #2a2c38; transform: scale(.98); }
#pc-roll { background: #2a2230; border-color: #4a2f3a; }
#pc-walk { background: #1e2a3a; border-color: #2f4a5a; }
#pc-read { background: #20302e; border-color: #2f5a52; }
#pc-back { background: #2a2733; border-color: #463f5a; }

/* die result popup */
.die-popup {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, background .2s ease;
}
.die-popup.show { opacity: 1; background: rgba(0,0,0,.5); pointer-events: auto; }
.die-card {
  text-align: center;
  padding: 26px 34px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
  transform: scale(.7);
  transition: transform .3s cubic-bezier(.2,1.35,.4,1);
  max-width: 80vw;
}
.die-popup.show .die-card { transform: scale(1); }
.die-symbol { font-size: 78px; line-height: 1; }
.die-label { margin-top: 8px; font-size: 24px; font-weight: 800; }
.die-sub { margin-top: 8px; font-size: 15px; color: var(--muted); max-width: 320px; }
.die-sub:empty { display: none; }

/* ---- Readable text over artwork (commander backgrounds) ---------------- */
.life, .ov-value {
  color: #fff;
  -webkit-text-stroke: 2.5px rgba(0,0,0,.9);
  paint-order: stroke fill;
}
.name {
  color: #fff;
  -webkit-text-stroke: 1px rgba(0,0,0,.85);
  paint-order: stroke fill;
}

/* ---- Commander artwork on a player card -------------------------------- */
.card.has-art { background-size: cover; background-position: center 28%; }
.card.has-art::after {              /* dim the art so the numbers stay legible */
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;                        /* above the art, below the tap zones (z1) */
  background: linear-gradient(180deg, rgba(0,0,0,.30), rgba(0,0,0,.58));
  pointer-events: none;
}

/* ---- Card search modal (commander picker) ------------------------------ */
#search-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 10px;
}
#search-input:focus { outline: none; border-color: var(--accent); }
.search-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 46vh;
  overflow: auto;
  margin-bottom: 12px;
}
.search-results button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.search-results button:active { background: #2a2c38; }
.search-results img.thumb { width: 38px; height: 28px; object-fit: cover; border-radius: 5px; flex: none; }
.search-results .hint { color: var(--muted); font-size: 14px; padding: 8px 2px; }
