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: linear-gradient(180deg, #f7fbff 0%, #f3f6ff 52%, #faf7ff 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 #ui-panel,
.ui-hidden #btn-panel-toggle,
.ui-hidden #hud {
  display: none;
}

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

#stage {
  grid-area: stage;
  min-width: 0;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.55));
  border: 1px solid rgba(0, 0, 0, 0.06);
}

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

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

.fullscreen-button {
  z-index: 2;
}

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.hud-field {
  position: absolute;
  pointer-events: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 10px 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
}

.hud-field > span {
  font-size: 12px;
  font-weight: 900;
  color: #2e3b55;
}

.hud-input {
  width: 76px;
  height: 38px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.95);
  color: #1f2a44;
  outline: none;
  font-size: 16px;
}

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

.stepper {
  display: inline-flex;
  align-items: center;
  height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.95);
  overflow: hidden;
}

.stepper .input {
  width: 72px;
  height: 42px;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: center;
  padding: 0 6px;
}

.step-btn {
  width: 34px;
  height: 42px;
  border: 0;
  background: rgba(77, 135, 255, 0.14);
  color: #1f2a44;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}

.step-btn:active {
  background: rgba(77, 135, 255, 0.24);
}

.exam-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  margin-top: 0;
}

.cmp-buttons {
  display: none;
}

.paint-target {
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(77, 135, 255, 0.14);
  color: #1f2a44;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.ui-panel {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 4;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 18px;
  padding: 22px 12px 12px;
  box-sizing: border-box;
  backdrop-filter: blur(10px);
  transform: translateY(0);
  transition: transform 180ms ease;
}

.panel-hidden .ui-panel {
  transform: translateY(calc(100% - 18px));
}

.panel-hidden .panel-handle svg {
  transform: rotate(180deg);
}

.panel-handle {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  width: 46px;
  height: 30px;
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  color: #2b3a55;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.panel-handle svg {
  transition: transform 180ms ease;
}

.ui-panel .panel-inner {
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 128px;
  gap: 12px;
  align-items: stretch;
}

.panel-main {
  min-width: 0;
}

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

.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab {
  appearance: none;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.9);
  color: #1f2a44;
  border-radius: 14px;
  height: 34px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
}

.tab.active {
  background: rgba(77, 135, 255, 0.16);
  border-color: rgba(77, 135, 255, 0.28);
}

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

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

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

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.row-compact {
  margin-top: 10px;
}

.mode-exam .row-compact {
  flex-wrap: nowrap;
  align-items: center;
}

.row.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.row.form-grid > * {
  min-width: 0;
}

.row.form-grid .btn {
  white-space: nowrap;
  min-width: 72px;
  justify-self: end;
}

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

.row.form-grid .inline {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.inline > span {
  font-size: 14px;
  font-weight: 800;
  color: #2e3b55;
  white-space: nowrap;
}

.input,
.select {
  height: 42px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.95);
  color: #1f2a44;
  outline: none;
  font-size: 16px;
}

.input {
  width: 100%;
}

.input.ok {
  border-color: rgba(55, 190, 120, 0.75);
  box-shadow: 0 0 0 3px rgba(55, 190, 120, 0.16);
}

.input.bad {
  border-color: rgba(255, 92, 92, 0.75);
  box-shadow: 0 0 0 3px rgba(255, 92, 92, 0.16);
}

.input.flash {
  border-color: rgba(255, 92, 92, 0.9);
  box-shadow: 0 0 0 3px rgba(255, 92, 92, 0.18);
  animation: input-shake 160ms linear 0s 2;
}

@keyframes input-shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  50% { transform: translateX(2px); }
  75% { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

.input.small,
.select.small {
  width: 110px;
}

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

.hint.compact {
  margin-top: 0;
}

.hint-steps {
  font-weight: 900;
  color: #1f2a44;
}

.hint-sub {
  margin-top: 4px;
}

.kpi {
  margin-top: 12px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.kpi.kpi-inline {
  display: none;
}

.kpi.kpi-side {
  margin-top: 0;
  padding: 0 10px;
  border-radius: 16px;
  height: 100%;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.kpi-label {
  font-size: 14px;
  font-weight: 900;
  color: #2e3b55;
}

.kpi-value {
  font-size: 22px;
  font-weight: 1000;
  color: #1f2a44;
  letter-spacing: 0.5px;
}

.kpi-fraction {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  line-height: 1;
  font-size: 56px;
  letter-spacing: 0.2px;
}

.kpi-fraction .kpi-bar {
  width: 56px;
  height: 6px;
  background: rgba(31, 42, 68, 0.55);
  border-radius: 3px;
  margin: 10px 0;
}

.kpi-fraction .kpi-num,
.kpi-fraction .kpi-den {
  font-weight: 1000;
}

.kpi-fraction .kpi-num,
.kpi-fraction .kpi-den {
  font-size: 1em;
}

.hidden {
  display: none !important;
}

.mode {
  margin-top: 12px;
}

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

.btn.small {
  height: 40px;
  border-radius: 14px;
  padding: 0 14px;
  font-size: 16px;
}

.btn.primary.small {
  height: 40px;
}

.btn:hover {
  background: #f7f9ff;
}

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

.btn.primary {
  background: rgba(77, 135, 255, 0.16);
  border-color: rgba(77, 135, 255, 0.28);
  color: #2b3a55;
}

.btn.primary:hover {
  background: rgba(77, 135, 255, 0.22);
}

.msg {
  margin-top: 10px;
  min-height: 18px;
  font-size: 14px;
  color: #2e3b55;
}

.teaching-layout #layout {
  padding: 12px;
}

.teaching-layout #panel {
  border-radius: 16px;
}

.teaching-layout .panel-top {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
  border-radius: 14px;
  padding: 8px 10px;
  z-index: 2;
}

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

.teaching-layout .row.form-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
}

.teaching-layout .row.form-grid .btn.primary {
  height: 38px;
  font-size: 16px;
  border-radius: 12px;
}

@media (max-width: 460px) {
  .row.form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .row.form-grid .btn {
    grid-column: 1 / -1;
    justify-self: stretch;
    min-width: 0;
  }
}

.teaching-layout .panel-title {
  font-size: 20px;
}

.teaching-layout .hint {
  font-size: 16px;
  line-height: 1.6;
}

.teaching-layout .inline > span {
  font-size: 14px;
}

.teaching-layout .input,
.teaching-layout .select {
  height: 38px;
  border-radius: 12px;
  font-size: 16px;
}

.teaching-layout .btn.tiny {
  height: 38px;
  border-radius: 12px;
  padding: 0 14px;
  font-size: 16px;
}

.teaching-layout .kpi-value {
  font-size: 26px;
}

.teaching-layout .msg {
  font-size: 14px;
}

.ui-collapsed #panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  top: auto;
  transform: none;
  width: auto;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  backdrop-filter: none;
  overflow: visible;
  z-index: 10;
}

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

.ui-collapsed .panel-top {
  justify-content: flex-end;
}

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

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

  #panel {
    width: auto;
    border-radius: 16px;
    max-height: 44vh;
  }

  .ui-panel .panel-inner {
    max-width: none;
    grid-template-columns: 1fr 110px;
    gap: 10px;
  }

  .kpi.kpi-side {
    padding: 10px 8px;
  }

  #practice-ui .row-compact {
    flex-direction: column;
    align-items: stretch;
  }

  #practice-ui .hud-inline {
    width: 100%;
  }

  #practice-ui .inline {
    justify-content: space-between;
  }

  #practice-ui .hint.compact {
    width: 100%;
  }

  .exam-controls {
    width: 100%;
  }
}
