* {
  box-sizing: border-box;
}

:root {
  --bg: #16181d;
  --panel-bg: #1e2128;
  --panel-border: #2c303a;
  --text: #e8e9ec;
  --text-dim: #9aa0ac;
  --accent: #5b8cff;
  --accent-hover: #7aa2ff;
  --danger: #ff6b6b;
  --warn-bg: #3a2e14;
  --warn-border: #6b5416;
  --warn-text: #f2c94c;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel-bg);
}

header h1 {
  display: inline-block;
  margin: 0;
  font-size: 1.25rem;
}

.product-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 9px;
  vertical-align: middle;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(91, 140, 255, 0.14);
  border-radius: 999px;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

#layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

#panel {
  width: 340px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 16px;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
}

.control-group {
  margin-bottom: 22px;
}

.control-group h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 10px;
}

label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 10px;
}

label.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

label.checkbox-row input {
  width: auto;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  margin-top: 4px;
  padding: 7px 8px;
  background: #12141a;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.88rem;
}

input[type="range"] {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--accent);
}

.range-value {
  color: var(--text);
  font-size: 0.78rem;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row label {
  flex: 1;
}

.primary-btn {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.secondary-btn {
  width: 100%;
  padding: 8px;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--accent);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.secondary-btn:hover {
  background: rgba(91, 140, 255, 0.1);
}

.secondary-btn:disabled {
  color: var(--text-dim);
  border-color: var(--panel-border);
  cursor: not-allowed;
  background: transparent;
}

.text-row {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: #191c22;
}

.text-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.text-row-title {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.remove-text {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
}

.warning {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.8rem;
  margin-bottom: 12px;
}

.warning.hidden {
  display: none;
}

#viewport {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at 50% 40%, #22262f 0%, #14161b 100%);
}

#canvas-container {
  position: absolute;
  inset: 0;
}

#canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-dim);
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 10px;
  border-radius: 12px;
  pointer-events: none;
  white-space: nowrap;
}

/* Phones and small tablets: stack the 3D preview above the controls
   instead of squeezing them side by side. */
@media (max-width: 760px) {
  header {
    padding: 12px 16px;
  }

  #layout {
    flex-direction: column;
    overflow-y: auto;
  }

  #viewport {
    order: 1;
    width: 100%;
    height: 42vh;
    height: 42dvh;
    flex-shrink: 0;
  }

  #panel {
    order: 2;
    width: 100%;
    flex: 1;
    border-right: none;
    border-top: 1px solid var(--panel-border);
  }

  .hint {
    font-size: 0.68rem;
    white-space: normal;
    text-align: center;
    max-width: 90%;
  }

  input[type="number"],
  input[type="text"],
  select {
    padding: 10px 10px;
    font-size: 1rem;
  }

  .primary-btn,
  .secondary-btn {
    padding: 12px;
  }

  /* Native checkbox/× controls default to tiny tap targets — widen the
     actual hit area without changing how big they look. */
  label.checkbox-row {
    padding: 8px 0;
  }

  label.checkbox-row input {
    width: 18px;
    height: 18px;
  }

  .remove-text {
    padding: 8px 10px;
    min-width: 40px;
    min-height: 40px;
  }
}

/* Narrow phones: stacking the paired Size/Engrave-depth fields avoids the
   label text wrapping into two lines in a cramped half-width column. */
@media (max-width: 420px) {
  .field-row {
    flex-direction: column;
    gap: 0;
  }
}
