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;
}

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

.edge-label {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 8px 18px rgba(20, 30, 60, 0.12);
  color: #1f2a44;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.2px;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.edge-label .var {
  font-style: italic;
}

.edge-label.a { box-shadow: 0 8px 18px rgba(255, 200, 77, 0.18); }
.edge-label.b { box-shadow: 0 8px 18px rgba(77, 135, 255, 0.16); }
.edge-label.c { box-shadow: 0 8px 18px rgba(70, 214, 168, 0.16); }

.face-bubble {
  position: absolute;
  transform: translate(-50%, -70%);
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 14px 28px rgba(20, 30, 60, 0.18);
  color: #1f2a44;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.2px;
  backdrop-filter: blur(10px);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.face-bubble.show {
  opacity: 1;
  transform: translate(-50%, -85%);
}

.face-bubble .mul {
  font-weight: 900;
}

.face-bubble.merge-hint {
  border-color: rgba(44, 198, 120, 0.28);
  box-shadow: 0 14px 28px rgba(44, 198, 120, 0.16);
}

.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-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;
}

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

.inline input[type="number"] {
  width: 62px;
  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;
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.btn:hover {
  background: #f7f9ff;
}

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

.btn.tiny {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
}

.answers {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

.answer {
  --card: rgba(70, 214, 168, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.75);
}

.answer[data-field="area"] { --card: rgba(255, 200, 77, 0.18); }
.answer[data-field="vol"] { --card: rgba(77, 135, 255, 0.18); }

.answer.active {
  box-shadow: 0 0 0 4px var(--card);
}

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

.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;
}

.tag-msg {
  margin-top: 6px;
  min-height: 16px;
  font-size: 12px;
  line-height: 1.3;
  color: #d14157;
}

.kv-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 72px 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);
}

.group-merge {
  background: rgba(234, 255, 243, 0.6);
  border-color: rgba(44, 198, 120, 0.2);
}

.group-merge .row {
  flex-wrap: nowrap;
}

.group-merge .row .inline .select {
  padding: 6px 8px;
}

.group-cut {
  background: rgba(255, 248, 220, 0.62);
  border-color: rgba(255, 200, 77, 0.28);
}

.group-cut .merge-tip {
  border-color: rgba(255, 200, 77, 0.34);
}

.cut-panel {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cut-panel .select {
  padding: 6px 8px;
}

.merge-tip {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px dashed rgba(44, 198, 120, 0.28);
  font-size: 12px;
  line-height: 1.5;
  color: #2e3b55;
  display: none;
}

.merge-tip.show {
  display: block;
}

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

.piece-label {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 8px 18px rgba(20, 30, 60, 0.12);
  color: #1f2a44;
  font-weight: 800;
  font-size: 12px;
  line-height: 1.35;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.group-compare {
  background: rgba(246, 240, 255, 0.68);
  border-color: rgba(120, 90, 210, 0.18);
}

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

.cmp-row {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 70px 1fr 20px 1fr 46px;
  align-items: center;
  gap: 8px;
}

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

.cmp-num {
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 900;
  color: #1f2a44;
  text-align: center;
}

.cmp-mid {
  text-align: center;
  color: #7a6aa8;
  font-weight: 900;
}

.cmp-trend {
  text-align: center;
  font-size: 12px;
  font-weight: 900;
  color: #1f2a44;
}

.cmp-trend.up { color: #1c8f52; }
.cmp-trend.down { color: #d14157; }
.cmp-trend.flat { color: #54607a; }

.msg {
  margin-top: 12px;
  font-size: 12px;
  line-height: 1.5;
  color: #1f2a44;
  min-height: 18px;
  white-space: pre-line;
}

.mode-practice #btn-hint {
  display: none;
}

.mode-exam #btn-hint {
  display: inline-flex;
}

.mode-exam .mode-practice {
  display: none;
}

@media (max-width: 640px) {
  #layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    grid-template-areas: "stage" "panel";
  }

  #panel {
    width: auto;
    max-height: 38vh;
  }

  .ui-collapsed #layout {
    grid-template-rows: 1fr auto;
  }

  .ui-collapsed #panel {
    width: auto;
    max-height: none;
  }
}
