:root {
  --bg-primary: #000000;
  --bg-secondary: #0a0d10;
  --bg-tertiary: #131820;
  --bg-card: #1c222b;
  --text-primary: #ffffff;
  --text-secondary: #c2c8d0;
  --text-muted: #8f98a3;
  --accent-primary: #00d4ff;
  --accent-secondary: #4af0a6;
  --danger: #ff4f6d;
  --warning: #ffbe4d;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.45);
  --radius-sm: 8px;
  --radius-md: 8px;
}

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

html,
body {
  width: 600px;
  height: 600px;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

#app {
  width: 600px;
  height: 600px;
  padding: 8px;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen.hidden,
.hidden {
  display: none !important;
}

.header {
  min-height: 58px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header h1 {
  flex: 1;
  min-width: 0;
  font-size: 20px;
  line-height: 1.05;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.home-title h1 {
  flex: 0 1 auto;
}

.version-badge {
  flex: 0 0 auto;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  background: rgba(0, 212, 255, 0.14);
  color: var(--accent-primary);
  border: 1px solid rgba(0, 212, 255, 0.45);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.header-meta {
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

.content {
  flex: 1;
  min-height: 0;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.content::after {
  content: "";
  min-height: 1px;
}

.center-content {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.focusable {
  min-height: 88px;
  border: 2px solid transparent;
  transition:
    transform 240ms cubic-bezier(0.6, 0, 0.4, 1),
    border-color 180ms ease,
    box-shadow 180ms ease,
    background-color 180ms ease;
}

.focusable:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
  transform: scale(0.985);
}

.back-btn {
  width: 48px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 24px;
}

.nav-bar {
  min-height: 88px;
  padding-top: 0;
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.nav-item,
.primary-action,
.secondary-action,
.inline-action {
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  border: 2px solid transparent;
}

.nav-item {
  flex: 1;
  padding: 8px;
  font-size: 14px;
  font-weight: 700;
}

.nav-item.primary,
.primary-action {
  background: var(--accent-primary);
  color: #001217;
}

.nav-item.danger {
  background: rgba(255, 79, 109, 0.22);
  color: #ffd9df;
}

.primary-action,
.secondary-action {
  width: 100%;
  padding: 12px 16px;
  font-size: 18px;
  font-weight: 800;
}

.inline-action {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 800;
  background: var(--accent-primary);
  color: #001217;
}

.secondary-action {
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 17px;
}

.home-content {
  padding-top: 8px;
}

.hero-panel,
.state-panel,
.hint-panel,
.progress-note,
.answer-card,
.question-item {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hero-panel {
  padding: 16px;
  min-height: 214px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
}

.hero-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(0, 212, 255, 0.16);
  border: 2px solid rgba(0, 212, 255, 0.7);
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 900;
  color: var(--accent-primary);
}

.hero-panel h2 {
  font-size: 24px;
  line-height: 1.1;
}

.hero-panel p,
.hint-panel,
.progress-note,
.state-panel span,
.result-help {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.35;
}

.action-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: inline-grid;
  place-items: center;
  font-size: 23px;
  line-height: 1;
}

.camera-content,
.review-content {
  min-height: 0;
}

.camera-preview,
.review-image {
  width: 100%;
  height: 422px;
  object-fit: contain;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.state-panel,
.hint-panel,
.progress-note {
  padding: 10px 12px;
}

.state-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loading-spinner {
  width: 54px;
  height: 54px;
  border: 5px solid var(--bg-tertiary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--text-secondary);
  font-size: 17px;
}

.answer-card {
  flex: 1;
  min-height: 454px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.question-prompt {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.3;
}

.question-prompt p,
.final-answer p,
.reasoning-list p {
  margin: 0;
}

.answer-label {
  color: var(--accent-secondary);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.final-answer {
  font-size: 22px;
  line-height: 1.16;
  font-weight: 800;
}

.reasoning-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-left: 20px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.28;
}

.math {
  display: inline-flex;
  align-items: center;
  gap: 0.18em;
  padding: 0 0.12em;
  color: #f8fbff;
  font-family: "Times New Roman", Georgia, serif;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

.math-display {
  display: flex;
  width: fit-content;
  max-width: 100%;
  margin: 4px 0;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  background: rgba(0, 212, 255, 0.1);
  overflow-x: auto;
}

.math-frac {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  vertical-align: middle;
  line-height: 1;
  margin: 0 0.12em;
}

.math-frac > span:first-child {
  width: 100%;
  padding: 0 0.18em 0.08em;
  border-bottom: 1px solid currentColor;
  text-align: center;
}

.math-frac > span:last-child {
  padding: 0.08em 0.18em 0;
  text-align: center;
}

.math-box {
  display: inline-block;
  padding: 0.08em 0.3em;
  border: 1px solid currentColor;
  border-radius: 4px;
}

.math-sqrt {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.05em;
}

.math-sqrt > span {
  border-top: 1px solid currentColor;
  padding: 0.02em 0.08em 0;
}

.warning-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.warning {
  color: #ffe2ad;
  background: rgba(255, 190, 77, 0.12);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 12px;
}

.result-help {
  min-height: 28px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  background: rgba(19, 24, 32, 0.72);
  text-align: center;
}

.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 430px;
  overflow-y: auto;
}

.question-item {
  width: 100%;
  min-height: 88px;
  padding: 10px 12px;
  color: var(--text-primary);
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
}

.question-number {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(0, 212, 255, 0.16);
  color: var(--accent-primary);
  font-weight: 900;
}

.question-summary {
  min-width: 0;
}

.question-summary strong {
  display: block;
  font-size: 15px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.question-summary span {
  display: block;
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.error-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 79, 109, 0.16);
  color: var(--danger);
  border: 2px solid rgba(255, 79, 109, 0.65);
  font-size: 34px;
  font-weight: 900;
}

.error-message {
  max-width: 456px;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.35;
}

.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  z-index: 20;
  max-width: 536px;
  transform: translateX(-50%) translateY(-90px);
  border-radius: 24px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--accent-primary);
  padding: 12px 18px;
  font-size: 14px;
  transition: transform 240ms ease;
  pointer-events: none;
}

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

.toast.error {
  border-color: var(--danger);
}
