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

:root {
  --bg: #0a0a0f;
  --surface: #14141e;
  --surface-hover: #1e1e2e;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-muted: #8888a0;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 50%;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

/* ====== Skip Link ====== */
.skip-link {
  position: fixed;
  top: -100%;
  left: 8px;
  z-index: 999;
  padding: 8px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
}
.skip-link:focus {
  top: 8px;
}

/* ====== App Shell ====== */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  padding-top: var(--safe-t);
}

/* ====== Top Bar ====== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-t));
  flex-shrink: 0;
}

.topbar__title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.topbar__add {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 300;
  border-radius: var(--radius-full);
  background: var(--surface);
  transition: background 0.15s;
  line-height: 1;
}
.topbar__add:active {
  background: var(--surface-hover);
}

/* ====== Main Scroll Area ====== */
.main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 16px;
}

/* ====== Palette Grid ====== */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px;
  padding: 4px 0;
}

/* ====== Divider ====== */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0 12px;
}

/* ====== Swatch ====== */
.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-touch-callout: none;
}
.swatch:active {
  transform: scale(0.96);
}

.swatch__color {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s;
}
.swatch:hover .swatch__color {
  transform: scale(1.08);
}

.swatch__color--border {
  outline: 1px solid var(--border);
  outline-offset: -1px;
}

.swatch__label {
  font-size: 11px;
  color: var(--text-muted);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  letter-spacing: 0.2px;
}

/* Long-press delete indicator */
.swatch--deleting {
  animation: pulse 0.4s ease-in-out 2;
}
@keyframes pulse {
  0%, 100% { background: var(--surface); }
  50% { background: rgba(255, 59, 48, 0.15); }
}

/* ====== Full-Screen Mode ====== */
.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fullscreen__color {
  position: absolute;
  inset: 0;
  /* background-color set by JS */
}

/* ====== Brightness Overlay ====== */
.fullscreen__brightness {
  position: fixed;
  bottom: calc(40px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  min-width: 260px;
  max-width: 85vw;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.fullscreen__brightness.visible {
  opacity: 1;
  pointer-events: auto;
}

.fullscreen__slider-track {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.fullscreen__icon {
  font-size: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.fullscreen__slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.fullscreen__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: transform 0.1s;
}

.fullscreen__slider::-webkit-slider-thumb:active {
  transform: scale(1.15);
}

.fullscreen__slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.fullscreen__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

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