:root {
  --bg: #0f0f0f;
  --panel: #161616;
  --panel-2: #1c1c1c;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --muted: #999;
  --accent: #6cf;
  --green: #4ade80;
  --amber: #fbbf24;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.mono, .hash, code {
  font-family: "SF Mono", "Fira Code", ui-monospace, Menlo, monospace;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 600; font-size: 1.05rem; }
.brand .tld { color: var(--muted); font-weight: 400; }

.tabs { display: flex; gap: 0.35rem; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.is-active { color: var(--accent); border-color: var(--border); background: var(--panel-2); }

/* Header: logo + controls */
.header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.9rem;
}
.logo { display: block; width: 235px; max-width: 62%; height: auto; }
.controls { display: flex; align-items: center; gap: 0.9rem; margin-left: auto; }
.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 2.5rem;
  height: 2.5rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.iconbtn:hover { color: var(--accent); background: var(--panel-2); }
.iconbtn svg { width: 1.55rem; height: 1.55rem; }

/* Settings menu */
.settings {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}
.set-row { display: flex; align-items: center; gap: 0.8rem; }
.set-row + .set-row { margin-top: 0.55rem; }
.set-head { margin-top: 0.45rem; }
.set-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.opt-list { display: grid; gap: 0.15rem; margin-top: 0.4rem; }
.opt-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.opt-item:hover { background: var(--panel-2); }
.opt-item.active { background: rgba(102, 204, 255, 0.08); }
.opt-item input { accent-color: var(--accent); }
.opt-name { min-width: 3.6rem; color: var(--text); }
.opt-cfg { color: var(--muted); }
.hint { font-size: 0.78rem; }

/* stepper (dice / coin count) */
.stepper { display: inline-flex; align-items: center; gap: 0.5rem; }
.stepper button {
  width: 1.4rem; height: 1.4rem; line-height: 1;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 5px; cursor: pointer; font-size: 0.95rem;
}
.stepper button:hover { border-color: var(--accent); color: var(--accent); }
.stepper b { min-width: 1rem; text-align: center; color: var(--accent); }

/* number min/max/count */
.nums { display: inline-flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.nums .dash { color: var(--muted); }
.nums label {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.72rem; color: var(--muted);
}
.nums input {
  width: 3rem; padding: 0.2rem 0.35rem;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 5px; color: var(--text); font-size: 0.8rem;
  font-family: inherit;
}

/* Segmented control (delay) */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-opt {
  background: var(--panel-2);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--muted);
  padding: 0.35rem 0.9rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.seg-opt:last-child { border-right: none; }
.seg-opt:hover { color: var(--text); }
.seg-opt.is-active { background: rgba(102, 204, 255, 0.12); color: var(--accent); }

/* Layout */
main { max-width: 640px; margin: 0 auto; padding: 1rem 1rem 2rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.card.muted { color: var(--muted); text-align: center; padding: 3rem 1.5rem; }

/* Detail modal */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.6rem 1.5rem;
  display: grid;
  gap: 1.3rem;
}
.modal-close {
  position: absolute; top: 0.5rem; right: 0.6rem;
  width: 1.8rem; height: 1.8rem; line-height: 1;
  background: transparent; border: none; color: var(--muted);
  font-size: 1.4rem; cursor: pointer; border-radius: 6px;
}
.modal-close:hover { color: var(--text); background: var(--panel-2); }
.card.muted h1 { color: var(--text); margin-bottom: 0.5rem; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
h1 { font-size: 1.4rem; font-weight: 600; }
h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.9rem; }
.sub { color: var(--muted); font-size: 0.9rem; margin: 0.5rem 0 1.25rem; }
.sub a { color: var(--accent); }

/* Status pill */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 0 rgba(251,191,36,0.5);
}
.status.live .dot { background: var(--green); animation: pulse 2s infinite; }
.status.error .dot { background: #f87171; }
.status.off { opacity: 0.6; }
.status.off .dot { background: var(--muted); box-shadow: none; }

/* On/off control group */
.control { display: flex; align-items: center; gap: 0.7rem; }
.switch { position: relative; display: inline-block; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.2s, border-color 0.2s;
}
.slider::before {
  content: "";
  position: absolute;
  height: 24px;
  width: 24px;
  left: 2px;
  top: 2px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.switch input:checked + .slider { background: rgba(74, 222, 128, 0.25); border-color: var(--green); }
.switch input:checked + .slider::before { transform: translateX(22px); background: var(--green); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(74,222,128,0.5); }
  70% { box-shadow: 0 0 0 6px rgba(74,222,128,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}

/* Beacon */
.beacon { display: grid; gap: 0.7rem; }
.field { display: grid; gap: 0.2rem; }
.label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.value { font-size: 0.95rem; }
.hash {
  display: block;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  font-size: 0.8rem;
  color: var(--accent);
  word-break: break-all;
}
.hash.sig { color: var(--muted); }
.subnote { font-size: 0.72rem; color: var(--muted); }
.subnote a { color: var(--accent); }

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.9rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.fetched { font-size: 0.8rem; color: var(--muted); }
.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }

/* History */
.history { list-style: none; display: grid; gap: 0.35rem; }
.history li {
  /* fixed grid: round | time | output | eye (no marker column) */
  display: grid;
  grid-template-columns: 4.7rem 4rem 1fr 1.35rem;
  align-items: center;
  column-gap: 0.4rem;
  font-size: 0.8rem;
  /* fixed height sized for the tallest output (dice) so rows don't jump
     when switching output modes */
  min-height: 2.5rem;
  padding: 0.3rem 0.5rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.history .h-round { color: var(--accent); font-weight: 600; }
.history .h-time { color: var(--muted); white-space: nowrap; }
.history .h-out {
  color: var(--muted);
  display: flex;
  align-items: center;
  flex-wrap: nowrap;      /* keep output on one line so rows stay dice-height */
  gap: 0.05rem;
  min-width: 0;
  overflow: hidden;
}
.history .h-out .mono { white-space: nowrap; }
.history .h-eye { color: #666; display: inline-flex; cursor: pointer; padding: 0.2rem; }
.history .h-eye svg { width: 1rem; height: 1rem; }
.history .h-eye:hover { color: var(--accent); }

/* color swatch */
.history .h-out .swatch {
  width: 1.1rem; height: 1.1rem; border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.15); margin-right: 0.4rem; flex-shrink: 0;
}
/* coin flips */
.history .h-out .coin {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.35rem; height: 1.35rem; margin-right: 0.22rem; border-radius: 50%;
  font-size: 0.72rem; font-weight: 600; border: 1px solid var(--border);
}
.history .h-out .coin { color: #1a1a1a; }
.history .h-out .coin.h { background: linear-gradient(145deg, #f6d874, #d4a017); border-color: #b8860b; }
.history .h-out .coin.t { background: linear-gradient(145deg, #ececec, #a9a9a9); border-color: #8f8f8f; }

/* dice: CSS pips on a 3x3 grid (font-independent) */
.history .h-out .die {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 1.45rem; height: 1.45rem; padding: 0.16rem; margin-right: 0.28rem;
  vertical-align: middle; background: #eaeaea; border: 1px solid #bbb;
  border-radius: 4px; box-sizing: border-box; flex-shrink: 0;
}
.history .h-out .die i {
  width: 0.26rem; height: 0.26rem; border-radius: 50%;
  align-self: center; justify-self: center;
}
.history .h-out .die i.on { background: #1a1a1a; }
/* playing cards: colored suit symbol + rank */
.history .h-out .pcard {
  display: inline-flex;
  align-items: baseline;
  gap: 0.06rem;
  margin-right: 0.4rem;
  font-size: 1rem;
  line-height: 1;
  color: var(--text);
}
.history .h-out .pcard b { font-size: 0.72rem; font-weight: 700; }
.history .h-out .pcard.red { color: #f87171; }

/* number balls */
.history .h-out .ball {
  display: inline-block; min-width: 1.5rem; text-align: center;
  padding: 0.08rem 0.32rem; margin-right: 0.22rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.72rem; color: var(--accent);
}

/* circular-buffer slots: fixed positions, content rotates */
.history li.empty { opacity: 0.35; cursor: default; }
.history li.empty:hover { border-color: var(--border); }
.history li.empty .h-round { color: var(--muted); font-weight: 400; }
.history li.empty .h-eye { display: none; }
.history li.latest { border-color: var(--accent); background: rgba(102, 204, 255, 0.08); }
