:root {
  --bg:        #15131f;
  --surface:   #1b182a;
  --surface-2: #1c1930;
  --line:      #2c2740;
  --line-2:    #3a3358;
  --text:      #e8e6f0;
  --muted:     #8a83a8;
  --accent:    #7c63d8;
  --accent-2:  #5b3fa8;
  --amber:     #d8af52;
  --amber-bg:  #211c14;
  --gap:       12px;
}

* { box-sizing: border-box; }
/* Force the built-in [hidden] semantics to win over any class-level
   display: rule. Without !important, `.overlay { display: grid }` beats
   the UA stylesheet's `[hidden] { display: none }`, so setting
   el.hidden = true on the name overlay doesn't actually hide it. */
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; }
body { min-height: 100dvh; }

/* ---- Landing ---- */
body.landing { display: grid; place-items: center; padding: 24px; }
.landing-card { max-width: 420px; text-align: center; }
.brand { font-size: 36px; letter-spacing: -0.5px; margin: 0; }
.brand .dot { color: var(--accent); }
.tagline { color: var(--muted); margin: 6px 0 20px; }
.cta {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; padding: 14px 22px; border-radius: 12px;
  font-weight: 800; font-size: 16px; cursor: pointer;
}
.cta:active { transform: translateY(1px); }
.err { color: #ffb4a3; margin-top: 12px; font-size: 13px; }

/* ---- Room layout ---- */
body.room {
  display: grid; grid-template-rows: auto 1fr auto;
  height: 100dvh;
}
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.avatar-stack { display: flex; gap: 6px; }
.av {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: var(--bg);
}
.share {
  margin-left: auto; background: transparent; border: 1px solid var(--line-2);
  color: var(--text); width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; cursor: pointer;
}

/* ---- Feed ---- */
.feed { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: var(--gap); }
.roll {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
.roll.me { border-color: var(--accent-2); }
.roll.hidden { border-style: dashed; border-color: var(--amber); background: var(--amber-bg); }
.rh { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-bottom: 7px; }
.rh .av { width: 20px; height: 20px; font-size: 10px; }
.rh .name { font-weight: 700; }
.rh .ts   { margin-left: auto; color: var(--muted); font-size: 11px; }
.rh .lock { color: var(--amber); font-size: 11px; font-weight: 700; }

.dice { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.grp  { color: var(--muted); font-size: 11px; margin-right: 4px; }
.die  { position: relative; display: inline-grid; place-items: center; width: 30px; height: 30px; color: var(--accent); }
.die svg { position: absolute; inset: 0; }
.die .face { position: relative; z-index: 1; font-weight: 800; font-size: 12px; color: #fff;
             text-shadow: 0 1px 0 rgba(0,0,0,.5); }
.die .fill { fill: var(--surface-2); }
.die.max .fill { fill: var(--accent); }
.total { margin-left: 8px; font-weight: 800; font-size: 15px; }

/* ---- Dice tray ---- */
.tray {
  background: var(--surface-2); border-top: 1px solid var(--line);
  padding: 12px 14px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.tray-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
              color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.pool-summary { margin-left: auto; color: var(--text); font-weight: 700;
                text-transform: none; letter-spacing: 0; font-size: 13px; }
.tray-row { display: flex; gap: 8px; flex-wrap: wrap; }
.dbtn {
  flex: 1; min-width: 54px; padding: 10px 6px 8px; position: relative;
  background: #241f3a; border: 1px solid var(--line-2); border-radius: 10px;
  color: var(--accent); cursor: pointer;
}
.dbtn .label { display: block; margin-top: 4px;
               font-size: 10px; font-weight: 700; color: var(--muted); letter-spacing: .5px; }
.dbtn .pip {
  position: absolute; top: 4px; right: 6px;
  background: var(--accent-2); color: #fff; font-size: 10px; font-weight: 800;
  padding: 1px 6px; border-radius: 10px;
}
.dbtn:active { transform: translateY(1px); }
.dbtn svg { width: 32px; height: 32px; display: block; margin: 0 auto; }

.tray-actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.chip {
  flex: 1; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--line-2); border-radius: 10px;
  font-size: 13px; color: var(--muted); text-align: left; cursor: pointer;
}
.chip strong { color: var(--text); }
.link { background: none; border: none; color: var(--muted); font-size: 12px; cursor: pointer; }

button.roll {
  padding: 12px 26px; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; border-radius: 10px; font-weight: 800; font-size: 15px; color: #fff;
  cursor: pointer; min-width: 100px;
}
button.roll[disabled] { opacity: .4; cursor: not-allowed; }

/* ---- Overlays ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(10,8,18,.85);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.name-card {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 18px; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 12px;
}
.name-card h2 { margin: 0; font-size: 18px; }
.name-card input {
  background: var(--bg); border: 1px solid var(--line-2);
  color: var(--text); padding: 12px; border-radius: 10px; font-size: 16px;
}

/* ---- Hidden-target popover ---- */
.popover {
  position: absolute; background: var(--surface-2);
  border: 1px solid var(--line-2); border-radius: 10px;
  padding: 6px; min-width: 200px; z-index: 40;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.popover .opt {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.popover .opt:hover, .popover .opt.sel { background: #2a2440; }
