:root {
  --bg-deep: #12110f;
  --bg-page: #161513;
  --bg-card: #1c1a18;
  --bg-raised: #262421;
  --hairline: rgba(239, 233, 222, 0.08);
  --hairline-strong: rgba(239, 233, 222, 0.16);
  --text-primary: #efe9de;
  --text-secondary: #aaa398;
  --text-muted: #8a847a;
  --accent: #c9a255;
  --accent-dark: #19150d;
  --positive: #4cc38a;
  --negative: #e5484d;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  --tray-size: 368px;
  --cup-size: 76px;
}

@media (max-height: 760px) {
  :root {
    --tray-size: 320px;
    --cup-size: 68px;
  }
}

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

html, body {
  height: 100%;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 304px;
  height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  border-left: 1px solid var(--hairline);
  border-right: 1px solid var(--hairline);
  overflow: hidden;
}

/* Stage */
.stage {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 24px 20px;
  background: var(--bg-page);
  min-width: 0;
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 36px;
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 12px;
}

.course-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.wordmark {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.divider {
  color: var(--text-muted);
}

.course-title {
  color: var(--text-secondary);
  font-size: 13px;
}

.supplies {
  display: flex;
  align-items: center;
  gap: 16px;
  white-space: nowrap;
}

.supply-item {
  color: var(--text-secondary);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.supply-item strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 500;
  margin-left: 4px;
}

/* Guest Zone */
.guest-zone {
  text-align: center;
  max-width: 540px;
  margin: 8px auto 4px;
}

.guest-name {
  font-size: 24px;
  line-height: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.guest-trait {
  margin-top: 4px;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
}

.guest-dialogue {
  margin-top: 8px;
  min-height: 36px;
  font-size: 14px;
  line-height: 20px;
  color: var(--text-secondary);
}

/* Lacquer Tray */
.tray-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
  padding: 8px 0;
}

.lacquer-tray {
  position: relative;
  width: var(--tray-size);
  height: var(--tray-size);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #211e1a 0%, #151311 72%, #100f0d 100%);
  border: 1px solid rgba(201, 162, 85, 0.24);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 0 0 8px #181614, inset 0 0 0 9px rgba(239, 233, 222, 0.06);
  flex-shrink: 0;
}

.cups-ring {
  position: absolute;
  inset: 0;
}

/* Individual Goblet Slot: Entire circle is clickable; status lives strictly inside */
.cup-slot {
  position: absolute;
  width: var(--cup-size);
  height: var(--cup-size);
  margin-left: calc(var(--cup-size) / -2);
  margin-top: calc(var(--cup-size) / -2);
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--hairline-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 140ms var(--ease), border-color 140ms var(--ease), background-color 140ms var(--ease);
}

.cup-slot .cup-rim,
.cup-slot .cup-num,
.cup-slot .cup-state {
  pointer-events: none;
}

.cup-slot:hover:not(.is-empty) {
  border-color: rgba(239, 233, 222, 0.4);
  background: #221f1c;
}

.cup-slot:active:not(.is-empty) {
  transform: scale(0.96);
}

.cup-slot:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cup-slot.is-selected {
  border-color: var(--accent);
  background: #2b2418;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.cup-rim {
  width: calc(var(--cup-size) - 16px);
  height: calc(var(--cup-size) - 16px);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #382e23 0%, #241d16 70%, #191510 100%);
  border: 1px solid rgba(201, 162, 85, 0.32);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.cup-num {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 15px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.cup-state {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 13px;
  color: var(--text-muted);
}

.cup-slot.known-clean {
  border-color: rgba(76, 195, 138, 0.55);
}

.cup-slot.known-clean .cup-state {
  color: var(--positive);
}

.cup-slot.known-poison {
  border-color: rgba(229, 72, 77, 0.55);
}

.cup-slot.known-poison .cup-state {
  color: var(--negative);
}

.cup-slot.note-clean .cup-state {
  color: var(--positive);
}

.cup-slot.note-poison .cup-state {
  color: var(--negative);
}

/* Drained goblet stays in fixed slot */
.cup-slot.is-empty {
  cursor: default;
  background: #141311;
  border-style: dashed;
  border-color: var(--hairline);
}

.cup-slot.is-empty .cup-rim {
  background: #171614;
  border-color: rgba(239, 233, 222, 0.05);
}

.cup-slot.is-empty .cup-num {
  color: var(--text-muted);
  opacity: 0.4;
}

/* Corner badge: tappable on touch screens & desktop, right-click anywhere also cycles */
.cup-mark {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-deep);
  border: 1px solid var(--hairline-strong);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  pointer-events: auto;
  transition: border-color 140ms var(--ease), transform 140ms var(--ease);
}

.cup-mark:hover {
  border-color: rgba(239, 233, 222, 0.45);
  transform: scale(1.08);
}

.cup-slot.known-clean .cup-mark,
.cup-slot.note-clean .cup-mark {
  color: var(--positive);
  border-color: rgba(76, 195, 138, 0.5);
}

.cup-slot.known-poison .cup-mark,
.cup-slot.note-poison .cup-mark {
  color: var(--negative);
  border-color: rgba(229, 72, 77, 0.5);
}

/* Center Crown Well */
.crown-well {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 124px;
  height: 124px;
  margin-left: -62px;
  margin-top: -62px;
  border-radius: 50%;
  background: var(--bg-deep);
  border: 1px solid rgba(201, 162, 85, 0.22);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
}

.crown-label {
  font-size: 11px;
  line-height: 14px;
  color: var(--accent);
}

.crown-slots {
  display: flex;
  gap: 8px;
}

.crown-slot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px dashed rgba(201, 162, 85, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

.crown-slot.filled {
  border-style: solid;
  background: #241e14;
}

.crown-hint {
  font-size: 11px;
  line-height: 14px;
  color: var(--text-muted);
}

/* Action Bar: Two clean rows or single non-wrapping bar */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}

.mode-group {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.mode-btn {
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--hairline);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 140ms var(--ease), color 140ms var(--ease), border-color 140ms var(--ease);
}

.mode-btn:hover:not(:disabled) {
  background: var(--bg-raised);
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--bg-raised);
  color: var(--text-primary);
  border-color: rgba(201, 162, 85, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.mode-btn:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 15px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--bg-deep);
  border: 1px solid var(--hairline-strong);
  color: var(--text-muted);
}

.commit-group {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.selection-prompt {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.primary-btn {
  height: 36px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-dark);
  border: none;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transition: opacity 140ms var(--ease), transform 140ms var(--ease);
}

.primary-btn:hover:not(:disabled) {
  opacity: 0.92;
}

.primary-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.primary-btn:disabled {
  background: var(--bg-raised);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

.quiet-btn {
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 140ms var(--ease), color 140ms var(--ease);
}

.quiet-btn:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
}

/* Sidebar */
.ledger-sidebar {
  background: var(--bg-deep);
  border-left: 1px solid var(--hairline);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100vh;
  overflow: hidden;
}

.sidebar-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.block-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.mono-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-cell {
  background: var(--bg-card);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 11px;
  line-height: 14px;
  color: var(--text-muted);
  white-space: nowrap;
}

.stat-val {
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 22px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.accent-text {
  color: var(--accent);
}

.positive-text {
  color: var(--positive);
}

.negative-text {
  color: var(--negative);
}

.muted {
  color: var(--text-muted);
}

.law-list {
  list-style: none;
  background: var(--bg-card);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.law-list li {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  line-height: 18px;
}

.ledger-block {
  flex: 1;
  min-height: 0;
}

.ledger-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
}

.ledger-empty {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 18px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--hairline);
  border-radius: 8px;
}

.ledger-row {
  background: var(--bg-card);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ledger-top {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.ledger-tag {
  font-family: var(--font-mono);
  font-size: 12px;
}

.tag-calm {
  color: var(--text-secondary);
}

.tag-hesitate {
  color: var(--accent);
}

.tag-choked, .tag-poison {
  color: var(--negative);
}

.tag-clean {
  color: var(--positive);
}

.ledger-detail {
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-footer {
  display: flex;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}

/* Outcome Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 11, 10, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-card);
  border: 1px solid var(--hairline-strong);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.outcome-tag {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

.outcome-title {
  font-size: 22px;
  line-height: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.outcome-body {
  font-size: 14px;
  line-height: 22px;
  color: var(--text-secondary);
}

.outcome-truth {
  background: var(--bg-deep);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.share-card {
  background: var(--bg-deep);
  border: 1px solid rgba(201, 162, 85, 0.28);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 18px;
  color: var(--text-primary);
  white-space: pre-wrap;
  user-select: text;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

@media (max-width: 820px) {
  :root {
    --tray-size: 304px;
    --cup-size: 64px;
  }
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .stage {
    padding: 12px 16px 16px;
  }
  .stage-header {
    height: auto;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 8px;
  }
  .ledger-sidebar {
    height: auto;
    border-left: none;
    border-top: 1px solid var(--hairline);
  }
  .action-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .mode-group {
    justify-content: space-between;
  }
  .mode-btn {
    flex: 1;
    justify-content: center;
    padding: 0 8px;
  }
  .mode-btn kbd {
    display: none;
  }
  .commit-group {
    justify-content: space-between;
  }
}
