:root {
  --bg: #0c0715;
  --card: rgba(28, 18, 45, 0.82);
  --card-strong: rgba(42, 25, 64, 0.92);
  --line: rgba(245, 210, 137, 0.18);
  --text: #fff8e8;
  --muted: rgba(255, 248, 232, 0.68);
  --gold: #f4cb78;
  --gold-2: #ffe2a3;
  --violet: #8f5cff;
  --violet-2: #caa8ff;
  --danger: #ff6b6b;
  --ok: #75f0bc;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 5%, rgba(143, 92, 255, 0.34), transparent 30%),
    radial-gradient(circle at 85% 0%, rgba(244, 203, 120, 0.18), transparent 24%),
    linear-gradient(180deg, #13091f 0%, var(--bg) 100%);
  color: var(--text);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.026) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent 75%);
}

.app-shell {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.card {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  margin-bottom: 14px;
}

.hero { padding: 22px; }

.title-row, .section-head, .dice-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow, .small-label {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin: 0;
  font-size: 42px;
  line-height: 0.9;
  letter-spacing: 0.03em;
}

h2 {
  margin: 0;
  font-size: 18px;
}

.subtitle {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.orb {
  width: 66px;
  height: 66px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #160b23;
  background: linear-gradient(135deg, var(--gold), var(--violet-2));
  box-shadow: 0 0 34px rgba(244, 203, 120, 0.28);
}

.setup-card, .board-card, .message-card, .recent-card, .journal-card { padding: 16px; }

.mirror-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.mirror-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: #220d16;
  background: linear-gradient(135deg, var(--danger), var(--gold));
  font-size: 12px;
  font-weight: 850;
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--gold-2);
  font-size: 14px;
  font-weight: 700;
}

textarea {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  padding: 14px;
  resize: vertical;
  min-height: 108px;
  background: rgba(255,255,255,0.06);
  color: var(--text);
  outline: none;
  font: inherit;
}

textarea:focus { border-color: rgba(244,203,120,0.62); }

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  color: var(--text);
  font-weight: 600;
}

.check-row input { width: 20px; height: 20px; accent-color: var(--gold); }

.primary-btn, .ghost-btn {
  appearance: none;
  border: 0;
  border-radius: 18px;
  min-height: 48px;
  padding: 0 16px;
  color: #160b23;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
}

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--gold), var(--violet-2));
  box-shadow: 0 10px 30px rgba(143,92,255,0.22);
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary-btn.compact {
  width: auto;
  min-width: 108px;
}

.ghost-btn {
  min-height: 38px;
  color: var(--gold-2);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.10);
}

.ghost-btn.danger { color: var(--danger); }

.dice-card {
  padding: 14px;
  background: var(--card-strong);
}

.dice {
  width: 74px;
  height: 74px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 900;
  color: #150b20;
  background: linear-gradient(145deg, var(--gold-2), var(--gold));
  box-shadow: inset 0 -8px 16px rgba(0,0,0,0.16), 0 0 28px rgba(244,203,120,0.22);
}

.dice.rolling { animation: roll 680ms cubic-bezier(.2,.8,.2,1) infinite; }

@keyframes roll {
  0% { transform: rotate(0deg) scale(1); }
  30% { transform: rotate(16deg) scale(1.06); }
  60% { transform: rotate(-14deg) scale(0.96); }
  100% { transform: rotate(0deg) scale(1); }
}

.position-text {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 7px;
  margin-top: 14px;
}

.cell {
  aspect-ratio: 1;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  display: grid;
  place-items: center;
  position: relative;
  color: rgba(255,248,232,0.74);
  background: rgba(255,255,255,0.045);
  font-size: 12px;
  font-weight: 800;
}

.cell.active {
  color: #150b20;
  background: linear-gradient(135deg, var(--gold), var(--violet-2));
  box-shadow: 0 0 22px rgba(244,203,120,0.35);
}

.cell .mark {
  position: absolute;
  right: 3px;
  top: 2px;
  font-size: 10px;
}

.ai-text {
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.52;
  font-size: 15px;
}

.reformulate-btn {
  width: 100%;
  margin-top: 14px;
}

.continue-btn {
  width: 100%;
  margin-top: 10px;
}

.recent-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.recent-item {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 9px 10px;
  background: rgba(255,255,255,0.045);
  color: var(--muted);
  font-size: 13px;
}

.recent-item b { color: var(--text); }

.journal-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  max-height: 320px;
  overflow: auto;
}

.journal-item {
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.045);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.journal-item b { color: var(--text); }

.hidden { display: none !important; }

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: max(16px, env(safe-area-inset-bottom));
  margin: auto;
  max-width: 520px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(20, 10, 32, 0.94);
  border: 1px solid rgba(244,203,120,0.22);
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 10;
}

@media (max-width: 390px) {
  .board { gap: 5px; }
  .cell { border-radius: 9px; font-size: 11px; }
  .dice { width: 66px; height: 66px; }
  h1 { font-size: 38px; }
}
