html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at 30% 15%, #eef5ff 0%, #f3f0ff 55%, #f6fbff 100%);
}

.ui-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #2b3a55;
  letter-spacing: 0.5px;
}

.ui-hidden .ui-loading {
  display: flex;
}

.ui-hidden #layout {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 1fr;
  grid-template-areas: "stage";
}

.ui-hidden #panel {
  display: none;
}

#layout {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: 1fr;
  grid-template-areas: "stage panel";
  gap: 16px;
  padding: 16px;
  box-sizing: border-box;
}

#panel {
  grid-area: panel;
  width: 360px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 18px;
  padding: 14px 14px 12px;
  box-sizing: border-box;
  backdrop-filter: blur(10px);
  overflow: auto;
}

#stage {
  grid-area: stage;
  min-width: 0;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
}

.v3d-container {
  position: relative;
  width: 100%;
  height: 100%;
}

.v3d-container canvas {
  touch-action: none;
}

.mark-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.face-mark {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 10px 20px rgba(20, 30, 60, 0.14);
  font-weight: 900;
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.2px;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.face-mark.plus {
  background: rgba(234, 255, 243, 0.92);
  color: #1b7f4b;
  border-color: rgba(44, 198, 120, 0.22);
}

.face-mark.minus {
  background: rgba(255, 235, 238, 0.92);
  color: #e53935;
  border-color: rgba(229, 57, 53, 0.22);
}

.face-mark.count {
  padding: 7px 12px;
  font-size: 12px;
}

.ui-collapsed #layout {
  grid-template-columns: minmax(0, 1fr) 56px;
  grid-template-areas: "stage panel";
}

.ui-collapsed #panel {
  width: 56px;
  padding: 10px;
  overflow: hidden;
}

.panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.panel-title {
  font-weight: 700;
  font-size: 16px;
  color: #1f2a44;
}

.panel-content {
  margin-top: 10px;
}

.ui-collapsed .panel-title {
  display: none;
}

.ui-collapsed .panel-content {
  display: none;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.kind-badge {
  margin-left: auto;
  height: 34px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.76);
  font-size: 12px;
  font-weight: 900;
  color: #2e3b55;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}

.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #39465f;
}

.inline input[type="number"] {
  width: 76px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 13px;
  outline: none;
  background: #fff;
}

.select {
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  background: #fff;
}

.hint {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.5;
  color: #39465f;
}

.dims {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 2px;
}

.btn {
  appearance: none;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #ffffff;
  color: #1f2a44;
  border-radius: 12px;
  height: 34px;
  padding: 0 12px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover {
  background: #f7f9ff;
}

.btn.success {
  background: #eafff3;
  border-color: rgba(44, 198, 120, 0.35);
}

.btn.tiny {
  height: 34px;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 13px;
}

.input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
  background: #fff;
}

.kv-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 82px minmax(0, 170px);
  gap: 10px;
  align-items: center;
}

.kv-k {
  font-size: 12px;
  color: #54607a;
  white-space: nowrap;
  text-align: right;
}

.panel-group {
  margin-top: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  padding: 10px;
}

.group-main {
  background: rgba(255, 255, 255, 0.72);
}

.explain {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(246, 240, 255, 0.68);
  border: 1px dashed rgba(120, 90, 210, 0.22);
  font-size: 12px;
  line-height: 1.5;
  color: #2e3b55;
}

.delta-card {
  margin-top: 10px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.delta-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #2e3b55;
}

.delta-line + .delta-line {
  margin-top: 8px;
}

.delta-tag {
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 900;
  letter-spacing: 0.2px;
}

.delta-tag.lose { background: rgba(255, 235, 238, 0.9); color: #e53935; }
.delta-tag.gain { background: rgba(220, 255, 234, 0.92); color: #00a84f; }
.delta-tag.net { background: rgba(234, 255, 243, 0.9); color: #1b7f4b; }

.delta-num {
  font-weight: 900;
  font-size: 14px;
  color: #1f2a44;
}

.delta-unit, .delta-arrow, .delta-eq {
  color: #5a6680;
}

.delta-formula {
  font-weight: 900;
  color: #1f2a44;
}

.msg {
  margin-top: 10px;
  min-height: 18px;
  font-size: 12px;
  line-height: 1.4;
  color: #d14157;
}

.quiz-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 30, 60, 0.18);
  backdrop-filter: blur(6px);
  padding: 16px;
  box-sizing: border-box;
}

.quiz-card {
  width: min(420px, 100%);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 20px 40px rgba(20, 30, 60, 0.22);
  padding: 14px;
  box-sizing: border-box;
}

.quiz-title {
  font-size: 14px;
  font-weight: 900;
  color: #1f2a44;
}

.quiz-q {
  margin-top: 10px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(246, 240, 255, 0.55);
}

.quiz-q-title {
  font-size: 12px;
  font-weight: 900;
  color: #2e3b55;
}

.quiz-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: #2e3b55;
}

.quiz-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.quiz-hint {
  margin-top: 10px;
  min-height: 16px;
  font-size: 12px;
  color: #d14157;
}

body.class-mode #layout { grid-template-columns: minmax(0, 1fr) 420px; }
body.class-mode #panel { width: 420px; padding: 16px 16px 14px; }
body.class-mode .panel-title { font-size: 18px; }
body.class-mode .btn, body.class-mode .btn.tiny { height: 40px; font-size: 15px; border-radius: 14px; }
body.class-mode .hint { font-size: 14px; }
body.class-mode .inline { font-size: 14px; }
body.class-mode .inline input[type="number"] { width: 88px; padding: 8px 10px; font-size: 15px; border-radius: 12px; }
body.class-mode .input { padding: 10px 12px; font-size: 15px; border-radius: 12px; }
body.class-mode .kv-k { font-size: 14px; }
body.class-mode .explain { font-size: 14px; }
body.class-mode .delta-line { font-size: 14px; }
body.class-mode .delta-num { font-size: 16px; }
body.class-mode .msg { font-size: 14px; }
body.class-mode .quiz-card { width: min(480px, 100%); }
body.class-mode .quiz-title { font-size: 16px; }
body.class-mode .quiz-q-title { font-size: 14px; }
body.class-mode .quiz-opt { font-size: 14px; }
body.class-mode .quiz-hint { font-size: 14px; }

body.ui-collapsed #layout { grid-template-columns: minmax(0, 1fr) 56px; grid-template-areas: "stage panel"; }
body.ui-collapsed #panel { width: 56px; padding: 10px; overflow: hidden; }
body.ui-collapsed .panel-title { display: none; }
body.ui-collapsed .panel-content { display: none; }
body.ui-collapsed .panel-actions { width: 100%; justify-content: center; }
body.ui-collapsed #btn-class-mode { display: none; }
body.ui-collapsed #btn-toggle-ui { width: 100%; padding: 0; white-space: nowrap; }

@media (max-width: 640px) {
  #layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      "stage"
      "panel";
  }
  #panel {
    width: 100%;
    border-radius: 18px;
    max-height: 42vh;
  }
}
