:root {
  --bg: #dde6f2;
  --panel: rgba(249, 251, 255, 0.88);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --text: #0f172a;
  --muted: #5f6f86;
  --line: rgba(148, 163, 184, 0.24);
  --warm: #f97316;
  --cool: #0ea5e9;
  --accent: #0b172a;
  --card-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  --card-shadow-strong: 0 18px 40px rgba(15, 23, 42, 0.12);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-strong: rgba(255, 255, 255, 0.9);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.72), transparent 24%),
    radial-gradient(circle at right center, rgba(209, 224, 241, 0.52), transparent 28%),
    linear-gradient(145deg, #e3ebf6 0%, #cfd9e8 100%);
  color: var(--text);
  font-family: "Pretendard", "SUIT", "Noto Sans KR", "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
}

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

.control-panel,
.canvas-stage {
  min-height: 0;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  grid-column: 2;
}

.control-panel > * {
  min-width: 0;
}

.panel-header,
.stage-header,
.section-head,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.action-row.compact {
  flex-wrap: wrap;
}

.action-card .action-row {
  flex-wrap: wrap;
}

.wide {
  flex: 1;
}

.small {
  padding-inline: 14px;
  min-height: 40px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(15, 23, 42, 0.42);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 3vw, 34px);
  line-height: 1.04;
  letter-spacing: -0.04em;
}

h2 {
  font-size: clamp(20px, 2.8vw, 26px);
  letter-spacing: -0.03em;
}

.card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.48), rgba(255, 255, 255, 0.12)),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(14px);
}

.card-label {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: -0.01em;
}

.card-copy {
  line-height: 1.55;
}

.subtle {
  color: rgba(71, 85, 105, 0.84);
}

.primary-button,
.ghost-button,
.mode-button {
  min-height: 50px;
  border-radius: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}

.primary-button:active,
.ghost-button:active,
.mode-button:active {
  transform: translateY(1px);
}

.primary-button {
  background: linear-gradient(135deg, #10203b, #1c2f4f);
  color: #f8fafc;
  box-shadow: 0 10px 24px rgba(16, 32, 59, 0.18);
}

.primary-button.warm {
  background: linear-gradient(135deg, #ff7b18, #ea580c);
}

.primary-button.cool {
  background: linear-gradient(135deg, #18a7e8, #0284c7);
}

.ghost-button,
.mode-button {
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.primary-button:hover,
.ghost-button:hover,
.mode-button:hover {
  box-shadow: var(--card-shadow);
}

.ghost-button:hover,
.mode-button:hover {
  border-color: rgba(100, 116, 139, 0.3);
  background: rgba(255, 255, 255, 0.96);
}

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

.mode-button.is-active {
  background: linear-gradient(135deg, #12305f, #2954cc);
  color: white;
  border-color: transparent;
  box-shadow: 0 12px 26px rgba(41, 84, 204, 0.26);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field span {
  font-size: 13px;
  color: var(--muted);
}

.field input {
  min-height: 48px;
  border-radius: 15px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.92);
  outline: none;
}

.field input:focus {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.status-text {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.compact-status {
  margin-top: 8px;
  font-size: 13px;
}

.total-card {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(237, 245, 255, 0.96));
  box-shadow: var(--card-shadow-strong);
}

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

.total-grid div {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.total-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.total-grid strong {
  font-size: 30px;
  letter-spacing: -0.03em;
}

.area-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 28vh;
  overflow: auto;
  padding-right: 2px;
}

.area-list-card,
.area-edit-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.area-edit-card {
  gap: 10px;
}

.area-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 13px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.18);
  text-align: left;
}

.area-item.is-active {
  border-color: rgba(14, 165, 233, 0.5);
  box-shadow: 0 10px 24px rgba(14, 165, 233, 0.14);
}

.area-item small {
  color: var(--muted);
  line-height: 1.4;
}

.canvas-stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
  grid-column: 1;
}

.stage-header {
  padding-inline: 4px;
}

.canvas-frame {
  position: relative;
  flex: 1;
  min-height: 60vh;
  border-radius: 28px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(232, 238, 247, 0.78)),
    #e7edf6;
  box-shadow: var(--card-shadow-strong);
}

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

.empty-hint {
  position: absolute;
  inset: 24px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  max-width: min(560px, calc(100% - 48px));
  margin: 0 auto;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

.empty-hint strong {
  font-size: clamp(20px, 3vw, 28px);
  letter-spacing: -0.03em;
  color: var(--text);
}

.empty-hint span {
  max-width: 560px;
  line-height: 1.6;
}

.empty-hint[hidden],
.empty-hint.is-hidden {
  display: none !important;
}

.help-dialog {
  width: min(92vw, 640px);
  border: none;
  border-radius: 24px;
  padding: 0;
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.25);
}

.help-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.help-dialog-body {
  display: grid;
  gap: 14px;
  padding: 20px;
  background: white;
}

.help-list {
  display: grid;
  gap: 8px;
  padding-left: 22px;
  line-height: 1.5;
}

.control-panel::-webkit-scrollbar,
.area-list::-webkit-scrollbar {
  width: 10px;
}

.control-panel::-webkit-scrollbar-thumb,
.area-list::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

@media (orientation: landscape) and (min-width: 900px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr minmax(360px, 450px);
    grid-template-rows: minmax(0, 1fr);
    height: 100svh;
    max-height: 100svh;
    gap: 10px;
    padding: 10px;
    overflow: hidden;
  }

  .control-panel {
    position: sticky;
    top: 12px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
    gap: 8px;
    height: calc(100svh - 20px);
    max-height: calc(100svh - 20px);
    overflow: auto;
    align-content: stretch;
    padding: 8px;
    border-radius: 24px;
    background: rgba(246, 249, 253, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  }

  .panel-header,
  .action-card,
  .area-actions-card,
  .total-card {
    grid-column: 1 / -1;
  }

  .card {
    padding: 10px;
    border-radius: 16px;
  }

  .primary-button,
  .ghost-button,
  .mode-button {
    min-height: 38px;
    border-radius: 12px;
    font-size: 15px;
  }

  .small {
    min-height: 34px;
    padding-inline: 12px;
  }

  .panel-header {
    align-items: flex-start;
    gap: 8px;
  }

  .panel-header .eyebrow {
    margin-bottom: 3px;
  }

  .panel-header h1 {
    font-size: clamp(24px, 2.2vw, 30px);
  }

  .panel-header .ghost-button {
    min-height: 36px;
    padding-inline: 14px;
    flex: none;
  }

  .stage-header {
    gap: 4px;
  }

  .stage-header .eyebrow {
    margin-bottom: 2px;
  }

  .stage-header h2 {
    font-size: clamp(18px, 2vw, 22px);
  }

  .card-label {
    margin-bottom: 6px;
    font-size: 11px;
  }

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

  .status-text {
    display: none;
  }

  .mode-grid {
    gap: 8px;
  }

  .total-grid {
    gap: 8px;
  }

  .total-grid div {
    padding: 12px;
    border-radius: 14px;
  }

  .total-grid strong {
    font-size: 22px;
  }

  .area-list {
    flex: 1;
    min-height: 0;
    max-height: none;
    gap: 6px;
  }

  .area-item {
    padding: 10px 12px;
    gap: 4px;
  }

  .area-item strong,
  .area-item small {
    font-size: 13px;
  }

  .area-edit-card .field {
    flex: 1;
    gap: 5px;
  }

  .area-edit-card .field span {
    font-size: 12px;
  }

  .area-edit-card .field input {
    min-height: 40px;
  }

  .area-edit-card .ghost-button {
    min-height: 38px;
  }

  .canvas-frame {
    min-height: calc(100svh - 72px);
  }
}

@media (orientation: portrait) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(48svh, 58svh) auto;
    gap: 12px;
    padding: 12px;
  }

  .control-panel {
    order: 2;
    grid-column: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-content: start;
  }

  .canvas-stage {
    order: 1;
    grid-column: 1;
  }

  .canvas-frame {
    min-height: 48svh;
  }

  .panel-header,
  .action-card,
  .total-card {
    grid-column: 1 / -1;
  }

  .area-list {
    max-height: 20svh;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .action-card,
  .total-card {
    grid-column: auto;
  }

  .mode-grid,
  .total-grid {
    grid-template-columns: 1fr;
  }

  .action-row {
    flex-wrap: wrap;
  }
}
