/* === Theme === */
:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #ddd;
  --primary: #2962FF;
  --primary-text: #fff;
  --secondary: #455a64;
  --secondary-text: #fff;
  --tertiary: #00897b;
  --tertiary-text: #fff;
  --danger: #d32f2f;
  --success: #2e7d32;
  --overlay-bg: rgba(0,0,0,0.6);
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1e1e1e;
    --text: #e0e0e0;
    --text-muted: #999;
    --border: #333;
    --primary: #448aff;
    --secondary: #78909c;
    --tertiary: #26a69a;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
  }
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* === Header === */
header {
  text-align: center;
  padding: 24px 16px 8px;
  position: relative;
}
header h1 {
  font-size: 1.4rem;
  font-weight: 700;
}
.lang-toggle {
  position: absolute;
  top: 24px;
  right: 16px;
  padding: 4px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
}
.lang-toggle:active { opacity: 0.7; }
.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

/* === Main === */
main {
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}

/* === Card === */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

/* === Fields === */
.field {
  margin-bottom: 16px;
}
.field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.2s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

/* === Searchable select === */
.searchable-select {
  position: relative;
}
.dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  list-style: none;
  z-index: 10;
  display: none;
  box-shadow: var(--shadow);
}
.dropdown.open { display: block; }
.dropdown li {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.95rem;
}
.dropdown li:hover,
.dropdown li.active {
  background: var(--primary);
  color: var(--primary-text);
}

/* === Color suggestions === */
.color-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.color-swatch-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color 0.2s;
}
.color-swatch-btn:hover,
.color-swatch-btn.active {
  border-color: var(--primary);
}
.color-swatch-btn .swatch-dot {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* === Color === */
.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
input[type="color"] {
  width: 48px;
  height: 42px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  cursor: pointer;
  background: var(--bg);
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border-radius: 4px; border: none; }

.color-hash {
  color: var(--text-muted);
  font-family: monospace;
  font-size: 1.1rem;
}
.hex-input {
  font-family: monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.hex-small { width: 60px !important; }

#extra-colors {
  margin-top: 8px;
}
.extra-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.extra-color-row .btn-remove {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--danger);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  flex-shrink: 0;
}

/* === Alpha === */
.alpha-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
  height: 6px;
}

/* === Temp === */
.temp-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.temp-row input[type="number"] {
  width: 80px;
  text-align: center;
}
.temp-sep {
  color: var(--text-muted);
}
.temp-unit {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* === Buttons === */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 12px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-secondary { background: var(--secondary); color: var(--secondary-text); }
.btn-tertiary { background: var(--tertiary); color: var(--tertiary-text); }
.btn-clear { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }

.btn-small {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-small:active { opacity: 0.7; }

.icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* === Library === */
.library-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.library-header h2 {
  font-size: 1rem;
  font-weight: 600;
}
.library-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.btn-danger {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
}

.library-list { }
.empty-msg {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 16px 0;
}

.library-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.library-item:hover { background: var(--bg); }
.library-item + .library-item { border-top: 1px solid var(--border); }

.swatch {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}
.swatch-multi {
  display: flex;
  overflow: hidden;
}
.swatch-multi span {
  flex: 1;
  height: 36px;
}

.library-info {
  flex: 1;
  min-width: 0;
}
.library-info .name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.library-info .detail {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.library-item .btn-remove {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.2rem;
  border-radius: 6px;
  flex-shrink: 0;
}
.library-item .btn-remove:hover {
  background: var(--danger);
  color: #fff;
}

/* === Status Bar === */
.status-bar {
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
}
.status-bar.error { background: #ffebee; color: var(--danger); }
.status-bar.success { background: #e8f5e9; color: var(--success); }
.status-bar.info { background: #e3f2fd; color: #1565c0; }

@media (prefers-color-scheme: dark) {
  .status-bar.error { background: #3e1a1a; }
  .status-bar.success { background: #1a3e1a; }
  .status-bar.info { background: #1a2a3e; }
}

/* === Overlay === */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }
.overlay-content {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  max-width: 320px;
  width: 90%;
}

/* === NFC Animation === */
.nfc-icon {
  width: 80px;
  height: 80px;
  color: var(--primary);
  margin-bottom: 16px;
}
.wave { opacity: 0; }
.nfc-animation .wave1 { animation: pulse 1.5s ease-out infinite; }
.nfc-animation .wave2 { animation: pulse 1.5s ease-out 0.3s infinite; }
.nfc-animation .wave3 { animation: pulse 1.5s ease-out 0.6s infinite; }

@keyframes pulse {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

#nfc-overlay-msg {
  margin-bottom: 20px;
  font-size: 1rem;
  color: var(--text);
}

/* === Tip === */
.tip-card {
  padding: 12px 16px;
}
.tip {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.tip-label {
  display: inline-block;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  vertical-align: middle;
  margin-right: 4px;
}
.tip-example {
  font-family: monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  background: var(--bg);
  padding: 8px 12px;
  border-radius: 6px;
  margin: 6px 0;
  text-align: center;
  letter-spacing: 0.5px;
}

/* === Credits === */
.credits {
  text-align: center;
  padding: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.credits ul {
  list-style: none;
  margin: 4px 0 8px;
}
.credits a {
  color: var(--primary);
  text-decoration: none;
}
.credits a:hover { text-decoration: underline; }
.credits-version {
  margin-top: 8px;
  opacity: 0.7;
}

/* === Color Choose Overlay === */
.color-choose-content h3 {
  font-size: 1rem;
  margin-bottom: 16px;
}
.color-choose-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}
.color-choose-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.2s;
}
.color-choose-option:hover {
  border-color: var(--primary);
}
.color-choose-option .swatch-dot {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.color-choose-option .color-label {
  font-family: monospace;
  font-size: 0.95rem;
  letter-spacing: 1px;
}

/* === Utility === */
.hidden { display: none !important; }
