:root {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --surface-alt: #F1EFEA;
  --border: #E4E0D8;
  --text: #22201D;
  --text-sub: #747068;
  --primary: #FF6B57;
  --primary-hover: #F0543F;
  --primary-soft: #FFF0ED;
  --accent: #2EC4B6;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(34, 32, 29, 0.06);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Top Toolbar */
.topbar {
  height: 60px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.meta-badge {
  font-size: 12px;
  color: var(--text-sub);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
}

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

.btn-secondary {
  background: #22201D;
  color: #FFFFFF;
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

/* Workspace Layout */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Canvas Stage */
.canvas-stage {
  flex: 1;
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #EFECE6;
  overflow: hidden;
}

#beadCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#beadCanvas:active {
  cursor: grabbing;
}

.canvas-floating-bar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 6px 10px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pill-btn {
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.divider-v {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}

.active-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(34, 32, 29, 0.92);
  color: #FFFFFF;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: calc(100% - 28px);
}

.swatch-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  flex-shrink: 0;
}

.banner-close {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #FFFFFF;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
}

/* Right Inspector */
.inspector {
  width: 370px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs {
  display: flex;
  padding: 8px 12px 0;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-badge {
  background: var(--surface-alt);
  color: var(--text);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
}

.tab.active .tab-badge {
  background: var(--primary-soft);
  color: var(--primary);
}

.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
}

.tab-panel.active {
  display: flex;
}

/* Progress Card */
.progress-card {
  background: var(--surface-alt);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 8px;
}

.progress-bar {
  height: 8px;
  background: #E2DED6;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.hint-text {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.4;
}

/* Color List */
.color-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.color-item:hover {
  border-color: #CFCAC0;
}

.color-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.color-item.completed {
  opacity: 0.65;
}

.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  position: relative;
}

.color-swatch::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
}

.color-info {
  flex: 1;
  min-width: 0;
}

.color-code-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.color-code {
  font-size: 15px;
  font-weight: 700;
}

.color-name {
  font-size: 13px;
  color: var(--text-sub);
}

.color-progress-sub {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 2px;
}

.color-count-pill {
  background: var(--surface-alt);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.color-item.active .color-count-pill {
  background: var(--primary);
  color: #FFFFFF;
}

/* Coordinates Panel */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-sub);
  padding: 24px;
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 10px;
}

.sub {
  font-size: 12px;
  color: var(--text-sub);
  margin: 2px 0 0;
}

.coords-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.selected-color-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius);
}

.selected-color-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.swatch-lg {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.selected-color-info h2 {
  margin: 0;
  font-size: 16px;
}

.selected-color-actions {
  display: flex;
  gap: 6px;
}

.coords-by-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface);
}

.row-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

.coord-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.coord-chip {
  padding: 5px 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  color: var(--text);
}

.coord-chip.done {
  background: #E6F8F5;
  border-color: var(--accent);
  color: #147D73;
  text-decoration: line-through;
}

/* Settings Panel */
.settings-group {
  margin-bottom: 16px;
}

.setting-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset-btn {
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preset-btn small {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-sub);
}

.preset-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

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

.inline-inputs input[type="number"] {
  width: 72px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  font-size: 14px;
  font-weight: 600;
}

.checkbox-inline {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-sub);
}

.select-input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: 14px;
  background: var(--surface);
}

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

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--surface-alt);
}

/* iPad Portrait / Narrow Screen Responsive */
@media (max-width: 860px) {
  .workspace {
    flex-direction: column;
  }

  .inspector {
    width: 100%;
    height: 44%;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .brand-text span {
    display: none;
  }
}
