:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --bg: #04070d;
  --panel: rgba(9, 15, 26, 0.84);
  --panel-strong: rgba(12, 21, 35, 0.96);
  --line: rgba(140, 176, 255, 0.16);
  --text: #ecf5ff;
  --muted: #a7bad3;
  --accent: #59b7ff;
  --accent-strong: #7ae0ff;
  --danger: #ff7d7d;
  --shadow: 0 22px 48px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(88, 132, 255, 0.14), transparent 34%),
    radial-gradient(circle at 80% 10%, rgba(65, 164, 255, 0.1), transparent 26%),
    var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
}

button,
input,
textarea,
select {
  font: inherit;
}

code,
kbd {
  font-family: ui-monospace, SFMono-Regular, SFMono-Regular, Menlo, Consolas, monospace;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 360px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
}

.control-panel,
.stage {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.control-panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.eyebrow,
.stage-label {
  margin: 0;
  color: var(--accent-strong);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
}

h1,
h2 {
  margin: 0;
  font-weight: 700;
}

h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
}

h2 {
  font-size: 1.05rem;
}

.intro,
.hint,
.tips,
.control-label,
.stat-label {
  color: var(--muted);
}

.intro,
.hint {
  line-height: 1.6;
}

.intro {
  margin: -10px 0 0;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(124, 153, 212, 0.12);
  border-radius: 20px;
  background: rgba(7, 13, 23, 0.62);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mode-pill {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(115, 200, 255, 0.28);
  background: rgba(56, 131, 255, 0.16);
  color: #dff7ff;
  font-size: 0.82rem;
}

.mode-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.mode-button,
.button {
  border: 1px solid rgba(137, 172, 245, 0.18);
  background: rgba(18, 31, 50, 0.92);
  color: var(--text);
  border-radius: 14px;
  padding: 11px 14px;
  cursor: pointer;
  transition:
    transform 120ms ease,
    background-color 120ms ease,
    border-color 120ms ease,
    box-shadow 120ms ease;
}

.mode-button:hover,
.mode-button:focus-visible,
.button:hover,
.button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(134, 201, 255, 0.32);
  background: rgba(24, 43, 70, 0.96);
}

.mode-button.is-active {
  border-color: rgba(117, 230, 255, 0.48);
  background:
    linear-gradient(180deg, rgba(56, 133, 255, 0.66), rgba(18, 74, 150, 0.82)),
    rgba(24, 48, 78, 0.96);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.button-primary {
  background:
    linear-gradient(180deg, rgba(82, 154, 255, 0.86), rgba(22, 86, 174, 0.94)),
    rgba(21, 74, 149, 0.96);
  border-color: rgba(117, 230, 255, 0.42);
}

.control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
}

.control-value {
  color: #f4fbff;
  font-variant-numeric: tabular-nums;
}

.control input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

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

.stat-card {
  padding: 14px;
  border-radius: 18px;
  background: rgba(16, 26, 42, 0.92);
  border: 1px solid rgba(124, 153, 212, 0.12);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-value {
  font-size: 1.3rem;
  color: #f4fbff;
}

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

.tips {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.55;
}

kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 2px 7px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  text-align: center;
  color: #f5fbff;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  min-height: calc(100vh - 48px);
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stage-header h2 {
  margin-top: 6px;
  font-size: 1.2rem;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 520px;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid rgba(125, 160, 231, 0.16);
  background: var(--panel-strong);
}

#cloth-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

body[data-mode="drag"] #cloth-canvas {
  cursor: grab;
}

body[data-mode="cut"] #cloth-canvas {
  cursor: crosshair;
}

body[data-mode="pin"] #cloth-canvas {
  cursor: cell;
}

.canvas-overlay {
  position: absolute;
  right: 18px;
  bottom: 18px;
  max-width: min(320px, calc(100% - 36px));
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(6, 11, 19, 0.72);
  border: 1px solid rgba(143, 192, 255, 0.14);
  color: var(--muted);
  line-height: 1.5;
  pointer-events: none;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
  }

  .stage {
    min-height: auto;
  }

  .canvas-wrap {
    min-height: 460px;
  }
}

@media (max-width: 640px) {
  .control-panel,
  .stage {
    border-radius: 22px;
  }

  .stats-grid,
  .action-row,
  .mode-buttons {
    grid-template-columns: 1fr;
  }

  .canvas-wrap {
    min-height: 400px;
  }

  .stage-header {
    align-items: flex-start;
    flex-direction: column;
  }
}
