:root {
  color-scheme: dark;
  font-family: Inter, "Microsoft YaHei", system-ui, sans-serif;
  background: #081014;
  color: #f8fafc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow: hidden;
  background: #081014;
}

button {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #ffd166;
  outline-offset: 3px;
}

#app,
#scene {
  position: fixed;
  inset: 0;
}

#scene {
  width: 100%;
  height: 100%;
  display: block;
}

.hidden {
  display: none !important;
}

.view {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: none;
}

.view.active {
  display: block;
}

.auth-view {
  padding: 40px;
  background:
    linear-gradient(135deg, rgba(246, 250, 255, 0.96), rgba(229, 239, 247, 0.94)),
    linear-gradient(90deg, rgba(18, 155, 211, 0.08), rgba(255, 96, 72, 0.05));
  color: #14212a;
}

.auth-brand {
  position: absolute;
  top: 52px;
  left: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.auth-brand span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #1e64d8;
  color: #fff;
  font-weight: 900;
}

.auth-brand strong {
  display: block;
  font-size: 32px;
  font-weight: 900;
}

.auth-brand p {
  margin: 5px 0 0;
  color: #61717d;
}

.auth-card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(520px, calc(100vw - 40px));
  transform: translate(-50%, -50%);
  padding: 26px;
  border: 1px solid rgba(20, 33, 42, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 24px 80px rgba(20, 33, 42, 0.12);
}

.auth-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
}

.auth-tabs button {
  min-width: 70px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #152027;
  font-weight: 900;
  cursor: pointer;
}

.auth-tabs button.active {
  background: #1e64d8;
  color: #fff;
}

.auth-card label {
  display: block;
  margin: 14px 0 8px;
  color: #17232b;
  font-weight: 900;
}

.auth-card input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(20, 33, 42, 0.14);
  border-radius: 8px;
  background: #f7fafc;
  color: #14212a;
  font-size: 16px;
}

.auth-card input:focus {
  outline: 2px solid rgba(30, 100, 216, 0.24);
  border-color: #1e64d8;
}

.auth-message {
  min-height: 22px;
  margin: 14px 0 18px;
  color: #65747e;
  font-size: 14px;
}

.auth-submit {
  min-width: 150px;
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: #009f7a;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(0, 159, 122, 0.22);
}

.wallpaper-view {
  overflow: hidden;
  background:
    linear-gradient(145deg, rgba(35, 18, 11, 0.97), rgba(92, 50, 27, 0.9));
}

.wallpaper-view::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    linear-gradient(115deg, transparent 0 42%, rgba(242, 192, 120, 0.16) 43%, transparent 48%),
    linear-gradient(70deg, transparent 0 58%, rgba(213, 154, 82, 0.15) 59%, transparent 64%);
  animation: wallpaperMove 8s linear infinite;
}

.wallpaper-view::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, transparent, #000 18%, #000 80%, transparent);
}

@keyframes wallpaperMove {
  from { transform: translate3d(-4%, -3%, 0) rotate(0deg); }
  to { transform: translate3d(4%, 3%, 0) rotate(4deg); }
}

.brand-mark {
  position: fixed;
  top: 24px;
  left: 28px;
  z-index: 2;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #f8fafc;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
}

.user-avatar {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.76);
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
}

.user-chip strong {
  font-size: 20px;
  font-weight: 900;
}

.hero-copy {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 24px;
  text-align: center;
}

.hero-copy p {
  margin: 0 0 14px;
  color: #f2c078;
  font-weight: 800;
}

.hero-copy h1 {
  max-width: 860px;
  margin: 0 0 28px;
  font-size: clamp(38px, 8vw, 86px);
  line-height: 0.98;
  letter-spacing: 0;
}

.fun-space-entry {
  position: absolute;
  z-index: 2;
  right: 28px;
  bottom: 24px;
  width: min(440px, calc(100vw - 56px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border: 1px solid rgba(242, 192, 120, 0.42);
  border-radius: 8px;
  background: rgba(42, 22, 13, 0.92);
  color: #fff2d8;
}

.fun-space-entry span,
.fun-space-entry strong {
  display: block;
}

.fun-space-entry span {
  color: #f2c078;
  font-weight: 900;
}

.fun-space-entry strong {
  margin-top: 4px;
  font-size: 24px;
}

.fun-space-entry p {
  margin: 7px 0 0;
  color: #e7c69b;
}

.fun-space-entry button {
  flex: 0 0 auto;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: #b55b2f;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.gate-button,
.scan-card button,
.camera-actions button,
.permission-layer button,
.ai-card button,
.game-hud button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: #ff6048;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(255, 96, 72, 0.28);
}

.gate-button {
  min-width: 188px;
  padding: 0 24px;
  font-size: 17px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.homework-view,
.camera-view,
.ai-view {
  padding: 22px;
  background: rgba(238, 244, 248, 0.96);
  color: #152027;
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #152027;
}

.topbar .user-chip {
  color: #152027;
}

.topbar .user-avatar {
  width: 38px;
  height: 38px;
  border-color: rgba(21, 32, 39, 0.14);
  font-size: 17px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.points-pill {
  min-width: 104px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  background: #101820;
  color: #fff;
  box-shadow: 0 12px 30px rgba(16, 24, 32, 0.14);
}

.points-pill span {
  color: #9fe8ff;
  font-size: 13px;
  font-weight: 800;
}

.points-pill strong {
  font-size: 20px;
  font-weight: 900;
}

.homework-layout {
  height: calc(100vh - 102px);
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 18px;
}

.scan-card,
.tool-grid button,
.camera-shell,
.ai-card {
  border: 1px solid rgba(19, 32, 39, 0.1);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 18px 52px rgba(21, 32, 39, 0.1);
}

.scan-card {
  display: grid;
  align-content: center;
  padding: 28px;
}

.scan-icon {
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 8px;
  background: #eaf8ff;
  color: #129bd3;
  font-size: 46px;
}

.scan-card h2 {
  margin: 0 0 10px;
  font-size: 34px;
}

.scan-card p {
  margin: 0 0 24px;
  color: #65747e;
  line-height: 1.7;
}

.scan-card button {
  width: 168px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.tool-grid button {
  padding: 22px;
  color: #152027;
  text-align: left;
  cursor: pointer;
}

.tool-grid button span {
  display: block;
  margin-bottom: 12px;
  color: #5d6d77;
}

.tool-grid button strong {
  display: block;
  font-size: 28px;
}

.tool-grid .fun-space-card {
  border-color: rgba(242, 192, 120, 0.88);
  background: linear-gradient(135deg, #2a160d, #6b3f24);
  color: #fff;
}

.tool-grid .fun-space-card span {
  color: #f2c078;
}

.tool-grid .fun-space-card small {
  display: block;
  margin-top: 12px;
  color: #f7dfbd;
  font-weight: 900;
}

.camera-view,
.ai-view {
  display: none;
  place-items: center;
}

.camera-view.active,
.ai-view.active {
  display: grid;
}

.camera-back {
  position: absolute;
  top: 22px;
  left: 22px;
  z-index: 4;
  min-width: 86px;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: #26343d;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(16, 24, 32, 0.18);
}

.camera-shell {
  width: min(920px, 100%);
  padding: 18px;
}

.camera-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  background: #11191e;
}

#cameraVideo,
#photoCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#photoCanvas {
  display: none;
}

.permission-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 24px;
  background: linear-gradient(145deg, rgba(11, 18, 23, 0.92), rgba(25, 40, 49, 0.88));
  color: #fff;
  text-align: center;
}

.permission-layer h2,
.ai-card h2 {
  margin: 0 0 10px;
  font-size: 34px;
}

.permission-layer p {
  max-width: 520px;
  margin: 0 0 20px;
  color: #c5d1da;
  line-height: 1.7;
}

.permission-layer button,
.upload-button {
  width: 150px;
  min-height: 42px;
  display: inline-grid;
  place-items: center;
  margin: 5px;
  border: 0;
  border-radius: 8px;
  background: #ff6048;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.upload-input {
  display: none;
}

.permission-layer .ghost {
  background: #26343d;
  box-shadow: none;
}

.camera-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.camera-actions button,
.ai-card button {
  min-width: 138px;
  padding: 0 18px;
}

.ai-card {
  width: min(760px, 100%);
  padding: 28px;
}

.ai-card.loading-only {
  width: min(520px, 100%);
  text-align: center;
}

.ai-card.loading-only h2 {
  margin: 0;
}

.ai-spinner {
  width: 54px;
  height: 54px;
  margin: 0 auto 18px;
  border: 5px solid #dce7ed;
  border-top-color: #b55b2f;
  border-radius: 50%;
  animation: aiSpin 0.8s linear infinite;
}

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

.analysis-status {
  min-height: 24px;
  margin: 10px 0 0;
  color: #60717b;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 8px;
  color: #129bd3;
  font-weight: 900;
}

.pipeline {
  display: grid;
  gap: 10px;
  margin: 22px 0;
}

.pipeline span {
  padding: 12px 14px;
  border-radius: 8px;
  background: #edf3f7;
  color: #60717b;
  font-weight: 800;
}

.pipeline span.done {
  background: #e6f8ed;
  color: #168348;
}

.pipeline span.active {
  outline: 2px solid rgba(181, 91, 47, 0.28);
  background: #fff0e2;
  color: #8f3d29;
}

.analysis-result {
  min-height: 92px;
  margin-bottom: 18px;
  padding: 16px;
  border-radius: 8px;
  background: #101820;
  color: #edf6fb;
  line-height: 1.7;
}

.fun-space-view {
  place-items: center;
  padding: 18px;
  overflow: auto;
  background: #2a160d;
  color: #fff2d8;
}

.fun-space-view.active {
  display: grid;
}

.fun-space-shell {
  width: min(1120px, calc(100vw - 36px));
  padding: 18px;
  border: 1px solid rgba(242, 192, 120, 0.35);
  border-radius: 14px;
  background: #3a2115;
  box-shadow: 0 24px 70px rgba(10, 4, 2, 0.42);
}

.fun-space-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.fun-space-topbar p {
  margin: 0 0 4px;
  color: #f2c078;
  font-weight: 900;
}

.fun-space-topbar h2 {
  margin: 0;
  color: #fff2d8;
  font-size: 30px;
}

.fun-space-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.fun-space-stats span {
  min-width: 108px;
  padding: 9px 12px;
  border-radius: 8px;
  background: #21120b;
  color: #d6a56f;
  font-weight: 800;
}

.fun-space-stats strong {
  color: #fff2d8;
  overflow-wrap: anywhere;
}

#funExit {
  min-width: 86px;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: #8f3d29;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

#funCanvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  border-radius: 12px;
  background: #21130d;
  box-shadow: inset 0 0 0 1px rgba(242, 192, 120, 0.3);
}

.fun-canvas-wrap {
  position: relative;
}

.fun-death-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  gap: 10px;
  background: #050302;
  color: #fff;
  text-align: center;
}

.fun-death-overlay strong {
  color: #ef563d;
  font-size: 58px;
  line-height: 1;
}

.fun-death-overlay span {
  color: #d5c8c0;
  font-weight: 800;
}

.fun-space-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  color: #e7c69b;
  font-weight: 800;
}

.fun-space-controls span,
.fun-message {
  padding: 9px 12px;
  border-radius: 8px;
  background: #21120b;
}

.touch-controls {
  display: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-controls button {
  width: 58px;
  height: 58px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background: rgba(16, 24, 32, 0.86);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

.touch-controls button.pressed {
  background: #ff6048;
  transform: translateY(2px);
}

.touch-controls .touch-action {
  width: 72px;
  background: #b55b2f;
}

.race-touch-controls {
  position: fixed;
  z-index: 4;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
  justify-content: space-between;
  pointer-events: none;
}

.touch-steering,
.touch-driving {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: auto;
}

.fun-message {
  margin-top: 10px;
  color: #fff2d8;
  font-weight: 900;
}

.game-hud,
.drive-hint,
.quiz-panel,
.result-panel {
  position: fixed;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #f8fafc;
  user-select: none;
}

.game-hud {
  top: 16px;
  left: 16px;
  right: 16px;
  flex-wrap: wrap;
}

.metric {
  min-width: 84px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(10, 14, 18, 0.68);
  backdrop-filter: blur(8px);
}

.metric span {
  display: block;
  color: #b9c2cc;
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
}

.game-hud button {
  width: 96px;
  box-shadow: none;
}

#backHome {
  background: #26343d;
}

.quiz-panel {
  left: 50%;
  bottom: 18px;
  width: min(720px, calc(100vw - 32px));
  transform: translateX(-50%);
  flex-direction: column;
  align-items: stretch;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(10, 14, 18, 0.75);
  backdrop-filter: blur(8px);
}

.quiz-panel p {
  margin: 0;
  font-weight: 800;
}

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

.answer-options button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #f4f8fb;
  color: #11191e;
  font-weight: 900;
  cursor: default;
}

.answer-options button:disabled {
  opacity: 1;
  box-shadow: none;
}

.answer-options button.correct {
  background: #35c46f;
  color: #fff;
}

.answer-options button.wrong {
  background: #e94b3c;
  color: #fff;
}

.drive-hint {
  top: 88px;
  right: 16px;
  width: 210px;
  align-items: center;
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 8px 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(10, 14, 18, 0.72);
  backdrop-filter: blur(8px);
  font-size: 13px;
}

.result-panel {
  inset: 0;
  z-index: 5;
  justify-content: center;
  padding: 24px;
  background: rgba(5, 10, 14, 0.52);
}

.result-card {
  width: min(760px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(10, 14, 18, 0.9);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
}

.result-card h2 {
  margin: 0 0 14px;
  font-size: 34px;
  color: #f8fafc;
}

.result-text {
  min-height: 128px;
  margin-bottom: 18px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: #edf6fb;
  line-height: 1.8;
  white-space: pre-wrap;
}

.result-card button {
  min-width: 120px;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: #ff6048;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

kbd {
  min-width: 26px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  padding: 0 7px;
  border-radius: 5px;
  background: #e9eef3;
  color: #14181c;
  font: 700 12px/1 Inter, system-ui, sans-serif;
}

@media (max-width: 760px) {
  body {
    overflow: auto;
    overscroll-behavior: none;
  }

  .view.active {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .homework-view,
  .camera-view,
  .ai-view {
    padding: 14px;
  }

  .homework-layout,
  .tool-grid {
    grid-template-columns: 1fr;
  }

  .homework-layout {
    height: auto;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
    height: auto;
    margin-bottom: 14px;
  }

  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .auth-view {
    padding: 18px;
  }

  .auth-brand {
    position: static;
    margin-bottom: 18px;
  }

  .auth-brand strong {
    font-size: 25px;
  }

  .auth-card {
    position: static;
    width: 100%;
    transform: none;
    padding: 20px;
  }

  .camera-view.active,
  .ai-view.active {
    align-content: start;
    padding-top: 76px;
  }

  .camera-stage {
    min-height: 260px;
    aspect-ratio: auto;
  }

  .camera-actions {
    flex-wrap: wrap;
  }

  .camera-actions button {
    flex: 1 1 120px;
    min-width: 0;
  }

  .permission-layer h2,
  .ai-card h2 {
    font-size: 26px;
  }

  .fun-space-view.active {
    display: block;
    padding: 10px;
    background: #2a160d;
    color: #fff2d8;
  }

  .fun-space-shell {
    width: 100%;
    min-height: calc(100dvh - 20px);
    padding: 12px;
  }

  .fun-space-topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .fun-space-topbar h2 {
    font-size: 23px;
  }

  .fun-space-stats {
    order: 3;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .fun-space-stats span {
    min-width: 0;
    padding: 8px;
  }

  .fun-space-stats span:last-child {
    grid-column: 1 / -1;
  }

  #funCanvas {
    aspect-ratio: 16 / 10;
    object-fit: fill;
  }

  .fun-space-controls {
    font-size: 13px;
  }

  .game-hud {
    top: max(8px, env(safe-area-inset-top));
    right: 8px;
    left: 8px;
    gap: 5px;
  }

  .metric {
    min-width: 62px;
    padding: 5px 7px;
  }

  .metric strong {
    font-size: 14px;
  }

  .game-hud button {
    width: auto;
    min-height: 36px;
    padding: 0 9px;
    font-size: 13px;
  }

  .answer-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .answer-options button {
    min-width: 0;
    padding: 5px;
    overflow-wrap: anywhere;
    font-size: 12px;
  }

  .quiz-panel {
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 70px);
    width: calc(100vw - 16px);
    padding: 9px;
    font-size: 13px;
  }

  .drive-hint {
    display: none !important;
  }
}

@media (hover: none), (pointer: coarse), (max-width: 760px) {
  .touch-controls:not(.hidden) {
    display: flex;
  }

  .fun-touch-controls {
    justify-content: space-between;
    gap: 10px;
    margin-top: 12px;
  }
}

@media (max-width: 420px) {
  .auth-brand p,
  .fun-space-controls span:last-child {
    display: none;
  }

  .hero-copy {
    padding: 76px 16px 24px;
  }

  .hero-copy h1 {
    font-size: 38px;
  }

  .scan-card,
  .tool-grid button,
  .ai-card {
    padding: 18px;
  }

  .scan-card h2 {
    font-size: 28px;
  }
}
