/* San7 emulator page — tokens from design-system/san7-web/MASTER.md (漆金墨韻) */
@font-face {
  font-family: 'Noto Serif TC';
  font-weight: 500;
  font-display: swap;
  src: url('fonts/noto-serif-tc-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Noto Serif TC';
  font-weight: 700;
  font-display: swap;
  src: url('fonts/noto-serif-tc-700.woff2') format('woff2');
}

:root {
  color-scheme: dark;
  --bg: #14100d;
  --surface: #1d1713;
  --surface-2: #282019;
  --surface-3: #33291f;
  --text: #f3e9d7;
  --text-muted: #b9a98f;
  --gold: #d4ae5c;
  --gold-strong: #e7c77a;
  --vermilion: #a9332a;
  --vermilion-hover: #bf3d32;
  --on-vermilion: #f2e6d6;
  --border: rgba(212, 174, 94, 0.2);
  --border-strong: rgba(212, 174, 94, 0.45);
  --ring: #e7c77a;
  --jade: #5fb59a;
  --danger: #ee6a5e;
  --info: #7db4d6;
  --font: 'Noto Serif TC', 'PMingLiU', 'Songti TC', serif;
  --radius: 4px;
  --radius-lg: 6px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 180ms;
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur: 0ms;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* 16px at 1080p, ~25px at 4K */
  font-size: clamp(13px, min(0.45vw + 7.4px, 0.8vh + 7.4px), 30px);
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.num {
  font-variant-numeric: tabular-nums;
}

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

svg {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:hover {
  background: var(--surface-3);
  border-color: var(--gold);
}
.btn-primary {
  background: var(--vermilion);
  border-color: #c9584d;
  color: var(--on-vermilion);
}
.btn-primary:hover {
  background: var(--vermilion-hover);
  border-color: var(--gold-strong);
}
.btn-gold {
  background: rgba(10, 8, 6, 0.7);
  border-color: var(--gold);
  color: var(--gold-strong);
}
.btn-ghost {
  background: rgba(20, 16, 13, 0.78);
}
.btn-lg {
  min-height: 3.1rem;
  font-size: 1.1rem;
}
.btn-icon {
  width: 2.75rem;
  padding: 0;
}
.btn-sm {
  min-height: 2.25rem;
  padding: 0 0.8rem;
  font-size: 0.85rem;
}
.btn-block {
  width: 100%;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.select {
  min-height: 2.5rem;
  padding: 0 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input[type='range'] {
  accent-color: var(--gold);
}

/* ---------- launch ---------- */
.launch {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end center;
  overflow: hidden;
}
.launch-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: slow-zoom 30s ease-out both;
}
@keyframes slow-zoom {
  from {
    transform: scale(1.06);
  }
}
.launch-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 40%, transparent 30%, rgba(10, 7, 5, 0.75) 100%),
    linear-gradient(180deg, transparent 50%, rgba(10, 7, 5, 0.94));
}
.launch-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 1rem;
  padding: 0 1rem 6vh;
  width: min(44rem, 100%);
}
.launch-sub {
  margin: 0;
  color: var(--gold-strong);
  font-size: 1.35rem;
  letter-spacing: 0.4em;
  text-shadow: 0 2px 8px #000;
}
.launch-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}
.launch-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.5rem;
  margin: 0;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(20, 16, 13, 0.72);
}
.opt {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-muted);
}
.launch-note {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  text-shadow: 0 1px 4px #000;
}

/* ---------- loading ---------- */
.loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 40%, #2a1f16, var(--bg) 70%);
}
.loading-card {
  width: min(30rem, 90vw);
  padding: 1.5rem 1.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.loading-title {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold-strong);
  letter-spacing: 0.3em;
}
.loading-step {
  margin: 0 0 0.75rem;
}
.loading-detail {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.bar {
  height: 0.6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #8a6a2f, var(--gold));
  transition: width 200ms linear;
}

/* ---------- stage ---------- */
.stage {
  position: fixed;
  inset: 0;
  background: #0b0907;
}
.frame {
  position: absolute;
  box-shadow: 0 0 0 1px rgba(212, 174, 94, 0.35), 0 0 60px rgba(0, 0, 0, 0.8);
}
.frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#canvas {
  outline: none;
  image-rendering: auto;
}
.stage[data-quality='pixel'] canvas {
  image-rendering: pixelated;
}
.stage[data-quality='enhance'] #canvas,
.stage[data-quality='enhance'] #boxedwine-webgl-canvas-0 {
  opacity: 0; /* #canvas still receives input; the HD canvas above shows the upscaled frame */
}
/* Boxedwine 26R2+ presents the screen on this canvas and takes input on #canvas below it */
#boxedwine-webgl-canvas-0,
#hd {
  pointer-events: none;
}
.stage:not([data-quality='enhance']) #hd {
  display: none;
}

/* toolbar: appears when the pointer is near the top or a control has focus */
.toolbar {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: rgba(20, 16, 13, 0.9);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(-0.5rem);
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}
.toolbar.is-visible,
.toolbar:focus-within {
  opacity: 1;
  transform: none;
}
.tb {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 0.6rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tb:hover {
  background: rgba(212, 174, 94, 0.14);
  border-color: var(--border-strong);
}
.tb[aria-pressed='false'] {
  color: var(--text-muted);
}
.tb-volume {
  width: 6rem;
}

/* tooltips */
[data-tip] {
  position: relative;
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 5;
  width: max-content;
  max-width: 16rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: #0e0b09;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 500;
  pointer-events: none;
}

/* ---------- movie ---------- */
.movie {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: #000;
}
.movie video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.movie .btn {
  position: absolute;
  right: 2rem;
  bottom: 2rem;
}

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 6, 4, 0.72);
  backdrop-filter: blur(4px);
}
.modal {
  width: min(44rem, 100%);
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  flex: 1;
  margin: 0;
  font-size: 1.25rem;
  color: var(--gold-strong);
}
.modal-body {
  padding: 0.5rem 1.25rem 1rem;
  overflow: auto;
}
.modal-body h3 {
  margin: 1rem 0 0.25rem;
  font-size: 1rem;
  color: var(--gold);
}
.modal-body ul {
  margin: 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.25rem;
}
.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}
.modal-sm {
  width: min(34rem, 100%);
}
.lost-text {
  margin: 0.5rem 0 0;
}
/* Wine's crash line, as printed */
.lost-detail {
  margin: 0.75rem 0 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid rgba(238, 106, 94, 0.5);
  border-radius: var(--radius);
  background: rgba(238, 106, 94, 0.08);
  color: var(--danger);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

/* ---------- account: notices, toast, menu ---------- */
.notice {
  margin: 0;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 0.92rem;
}
.notice[data-kind='ok'] {
  border-color: rgba(95, 181, 154, 0.5);
  background: rgba(95, 181, 154, 0.08);
  color: var(--jade);
}
.notice[data-kind='error'] {
  border-color: rgba(238, 106, 94, 0.5);
  background: rgba(238, 106, 94, 0.08);
  color: var(--danger);
}
.notice[data-kind='info'] {
  border-color: rgba(125, 180, 214, 0.45);
  background: rgba(125, 180, 214, 0.08);
  color: var(--info);
}
.notice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.toast {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 60;
  max-width: calc(100vw - 2rem);
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: rgba(20, 16, 13, 0.94);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(0.4rem);
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
  pointer-events: none;
}
.toast.is-visible {
  opacity: 1;
  transform: none;
}
.toast[data-kind='error'] {
  border-color: rgba(238, 106, 94, 0.6);
  color: var(--danger);
}

.account {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 5;
}
.account-btn {
  max-width: min(18rem, calc(100vw - 2rem));
}
.account-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: grid;
  min-width: 15rem;
  padding: 0.35rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  box-shadow: var(--shadow-lg);
}
.account-email {
  margin: 0 0 0.25rem;
  padding: 0.35rem 0.75rem 0.55rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  word-break: break-all;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.menu-item:hover {
  background: rgba(212, 174, 94, 0.12);
}

/* ---------- login and admin pages ---------- */
body.page {
  height: auto;
  min-height: 100%;
  overflow: auto;
}
.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1.5rem 1rem;
  background: radial-gradient(ellipse at 50% 30%, #2a1f16, var(--bg) 70%);
}
.auth-card {
  display: grid;
  gap: 1.25rem;
  width: min(26rem, 100%);
  padding: 2rem 1.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.auth-title {
  margin: 0;
  color: var(--gold-strong);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-align: center;
}
.auth-lead,
.auth-foot {
  margin: 0;
  color: var(--text-muted);
  text-align: center;
}
.auth-foot {
  font-size: 0.85rem;
}
.field {
  display: grid;
  gap: 0.4rem;
}
.field label {
  font-weight: 700;
}
.input {
  min-height: 2.75rem;
  padding: 0 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.input::placeholder {
  color: #8f8170;
}
.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border);
}

.admin {
  display: grid;
  gap: 1.5rem;
  max-width: 68rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}
.admin-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.admin-head h1 {
  margin: 0;
  color: var(--gold-strong);
  font-size: 1.5rem;
  letter-spacing: 0.1em;
}
.panel {
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.panel h2 {
  margin: 0;
  color: var(--gold-strong);
  font-size: 1.15rem;
}
.invite-form {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  align-items: end;
  gap: 0.75rem;
}
@media (max-width: 640px) {
  .invite-form {
    grid-template-columns: 1fr;
  }
}
.table-wrap {
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th,
.table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.table th {
  color: var(--text-muted);
  font-weight: 700;
}
.table .num {
  text-align: right;
}
.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.05rem 0.55rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.8rem;
}
.badge[data-kind='admin'] {
  color: var(--gold);
}
.badge[data-kind='ok'] {
  color: var(--jade);
}
.badge[data-kind='pending'] {
  color: var(--info);
}
.badge[data-kind='off'] {
  color: var(--danger);
}
