:root {
  color-scheme: light;
  --page: #fbfbf4;
  --ink: #27272a;
  --muted: #676b76;
  --line: #27272a;
  --paper: #ffffff;
  --soft: #eef7f1;
  --mint: #a7f3d0;
  --lemon: #fde68a;
  --rose: #fbcfe8;
  --violet: #ddd6fe;
  --sky: #bae6fd;
  --danger: #ef4444;
  --shadow: 6px 7px 0 rgba(39, 39, 42, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(186, 230, 253, 0.28), transparent 34rem),
    linear-gradient(135deg, rgba(167, 243, 208, 0.18), rgba(251, 207, 232, 0.14)),
    var(--page);
  color: var(--ink);
  font-family:
    "LXGW WenKai", "Kaiti SC", "STKaiti", "Microsoft YaHei", "PingFang SC", system-ui,
    sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.paper-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.32;
  background-image:
    linear-gradient(rgba(39, 39, 42, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(39, 39, 42, 0.03) 1px, transparent 1px);
  background-size: 24px 24px, 24px 24px;
  mask-image: linear-gradient(to bottom, #000, transparent 88%);
}

.app-shell {
  width: min(100%, 880px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 18px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar,
.status-strip,
.tabs,
.hero-panel,
.composer,
.work-card,
.mini-log,
.feed-card,
.modal-card {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
}

.brand h1,
.hero-panel h2,
.work-card h2,
.modal-card h2 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand h1 {
  font-size: clamp(1.45rem, 7vw, 2.25rem);
}

.brand p,
.eyebrow,
.hint,
.label,
.mini-log,
.modal-card p {
  color: var(--muted);
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.85rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.live-pill,
.status-strip div {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--mint);
  font-weight: 700;
  white-space: nowrap;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #22c55e;
  animation: dotPulse 1.5s infinite;
}

.icon-button,
.text-button,
.primary-button,
.ghost-button,
.chip,
.tab {
  min-height: 42px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 3px 4px 0 rgba(39, 39, 42, 0.14);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background-color 120ms ease;
}

.icon-button {
  width: 42px;
  padding: 0;
}

.text-button,
.primary-button,
.ghost-button,
.chip,
.tab {
  padding: 8px 12px;
  font-weight: 700;
}

button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 5px 6px 0 rgba(39, 39, 42, 0.14);
}

button:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 2px 0 rgba(39, 39, 42, 0.18);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

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

.status-strip div {
  min-width: 0;
  justify-content: space-between;
  border-radius: var(--radius);
  background: var(--soft);
}

.status-strip div:nth-child(2) {
  background: var(--sky);
}

.status-strip div:nth-child(3) {
  background: var(--rose);
}

.label {
  font-size: 0.8rem;
  font-weight: 700;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
}

.tab {
  width: 100%;
  background: #f3f4f6;
}

.tab.is-active {
  background: var(--lemon);
}

.view {
  display: none;
  min-height: 0;
  flex: 1;
}

.view.is-active {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

body.admin-route .status-strip,
body.admin-route .tabs,
body.admin-route #humanView,
body.admin-route #aiView,
body.admin-route #recordsView {
  display: none !important;
}

body.admin-route #adminView {
  display: flex;
}

.hero-panel,
.work-card {
  padding: 14px;
}

.hero-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(135deg, #ffffff 0%, #eef7f1 100%);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.hero-panel h2,
.work-card h2 {
  font-size: clamp(1.1rem, 5.2vw, 1.75rem);
}

.feed {
  flex: 1;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 4px 2px 4px;
}

.feed-card {
  padding: 12px;
  box-shadow: 4px 5px 0 rgba(39, 39, 42, 0.12);
}

.feed-card.user {
  align-self: flex-end;
  width: min(82%, 560px);
  background: #dcfce7;
}

.feed-card.ai {
  align-self: flex-start;
  width: min(88%, 620px);
  background: #faf5ff;
}

.feed-card.pending {
  background: #fef9c3;
}

.feed-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.feed-card p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.feed-card img {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.composer {
  position: sticky;
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  padding: 10px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
}

.mode-row,
.input-row,
.work-actions,
.tool-row,
.work-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-row {
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.chip {
  min-height: 36px;
  background: #f3f4f6;
}

.chip.is-active[data-mode="text"] {
  background: var(--lemon);
}

.chip.is-active[data-mode="draw"] {
  background: var(--rose);
}

.chip.is-active[data-answer-mode="text"] {
  background: var(--lemon);
}

.chip.is-active[data-answer-mode="draw"] {
  background: var(--rose);
}

.switch {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  color: var(--muted);
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  position: relative;
  width: 42px;
  height: 24px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #e5e7eb;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #fff;
  transition: transform 150ms ease;
}

.switch input:checked + span {
  background: var(--violet);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

textarea {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  line-height: 1.45;
  resize: none;
  outline: none;
}

textarea:focus {
  box-shadow: 0 0 0 3px rgba(186, 230, 253, 0.82);
}

.send-button {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--mint);
  color: var(--ink);
  box-shadow: 3px 4px 0 rgba(39, 39, 42, 0.15);
}

.hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
}

.primary-button {
  background: var(--mint);
}

.ghost-button {
  background: #f3f4f6;
}

.text-button {
  background: var(--violet);
  flex: 0 0 auto;
}

.work-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
}

.work-card:not(.active-work) {
  min-height: 240px;
  justify-content: center;
}

.work-head {
  align-items: flex-start;
  justify-content: space-between;
}

.timer {
  min-width: 56px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--lemon);
  padding: 6px 8px;
  text-align: center;
  font-weight: 800;
}

.timer.is-urgent {
  background: #fdba74;
}

.timer.is-critical {
  background: #fca5a5;
}

.timer-track {
  height: 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #e5e7eb;
}

.timer-track span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--mint);
  transition: width 220ms linear, background-color 120ms ease;
}

.answer-box {
  min-height: 160px;
}

.draw-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

canvas {
  width: 100%;
  aspect-ratio: 800 / 520;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  touch-action: none;
}

.tool-row {
  flex-wrap: wrap;
}

.tool.is-active {
  background: var(--sky);
}

.color-input {
  width: 42px;
  height: 42px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 3px;
}

.work-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.mini-log {
  padding: 12px;
  font-size: 0.9rem;
}

.mini-log h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 1rem;
}

.mini-log ul {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.record-list,
.admin-table,
.admin-dashboard {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.record-card,
.admin-row,
.admin-stat {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}

.record-card img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  margin: 8px 0;
}

.record-prompt {
  margin: 0;
  font-weight: 700;
}

.record-answer {
  margin: 8px 0 0;
  color: var(--muted);
  white-space: pre-wrap;
}

.record-answer-block {
  margin-top: 10px;
  border-top: 2px dashed var(--line);
  padding-top: 10px;
}

.admin-login input {
  min-height: 42px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.admin-stat {
  background: var(--soft);
}

.admin-stat span,
.admin-row span,
.admin-row small {
  display: block;
  color: var(--muted);
}

.admin-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 1.45rem;
}

.admin-row {
  display: grid;
  gap: 4px;
}

.admin-row strong,
.admin-row span {
  overflow-wrap: anywhere;
}

.hidden {
  display: none !important;
}

.modal {
  width: min(calc(100% - 32px), 520px);
  border: 0;
  padding: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(24, 24, 27, 0.46);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  padding: 20px;
}

.modal-card h2 {
  font-size: 1.5rem;
}

.modal-card p {
  margin: 12px 0 0;
  line-height: 1.7;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  transform: translateX(-50%) translateY(24px);
  min-width: min(360px, calc(100% - 32px));
  max-width: calc(100% - 32px);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  padding: 10px 12px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  z-index: 20;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes dotPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.35);
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding-inline: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .live-pill {
    display: none;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .status-strip {
    grid-template-columns: 1fr;
  }

  .tabs,
  .admin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-panel,
  .work-head {
    align-items: stretch;
    flex-direction: column;
  }

  .text-button,
  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .switch {
    width: 100%;
    margin-left: 0;
    justify-content: flex-end;
  }

  .feed-card.user,
  .feed-card.ai {
    width: 100%;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #171717;
    --ink: #f4f4f5;
    --muted: #c4c7cf;
    --line: #f4f4f5;
    --paper: #242428;
    --soft: #20352a;
    --mint: #166534;
    --lemon: #854d0e;
    --rose: #831843;
    --violet: #4c1d95;
    --sky: #075985;
    --shadow: 6px 7px 0 rgba(0, 0, 0, 0.42);
  }

  body {
    background:
      radial-gradient(circle at top left, rgba(7, 89, 133, 0.25), transparent 34rem),
      linear-gradient(135deg, rgba(22, 101, 52, 0.14), rgba(131, 24, 67, 0.1)),
      var(--page);
  }

  textarea,
  canvas,
  .color-input {
    background: #18181b;
  }

  .tab,
  .chip,
  .ghost-button {
    background: #303036;
  }

  .feed-card.user {
    background: #163a2a;
  }

  .feed-card.ai {
    background: #2e2540;
  }

  .feed-card.pending {
    background: #3a321d;
  }

  .record-card,
  .admin-row,
  .admin-stat,
  .admin-login input {
    background: #242428;
  }
}
