:root {
  --wall: #0c0c0c;
  --wall-2: #151515;
  --panel: #191919;
  --panel-2: #202020;
  --line: #2c2c2c;
  --ink: #f4f1ea;
  --ink-dim: #9a958c;
  --tape: #ffd400;
  --tape-ink: #171200;
  --red: #e53517;
  --ring: #050505;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --export-bar-h: calc(64px + var(--safe-bottom));
}

* { box-sizing: border-box; }

/* Ensure [hidden] always wins over component display rules (e.g. .btn). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--wall);
  color: var(--ink);
  font-family: 'Barlow Condensed', system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  /* concrete wall: layered radial soot + a subtle grain */
  background:
    radial-gradient(120% 80% at 15% -10%, #232323 0%, transparent 55%),
    radial-gradient(120% 90% at 110% 10%, #1c1c1c 0%, transparent 50%),
    var(--wall);
}

.wall-noise {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.app-header,
.app-main { position: relative; z-index: 1; }

/* ---------- Header ---------- */
.app-header {
  padding: calc(18px + var(--safe-top)) calc(20px + var(--safe-right)) 6px calc(20px + var(--safe-left));
  text-align: center;
}
.tape {
  display: inline-block;
  background: var(--tape);
  color: var(--tape-ink);
  padding: 6px 20px 4px;
  transform: rotate(-2deg);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  position: relative;
}
.tape::before, .tape::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 14px;
  background: rgba(255, 255, 255, 0.18);
}
.tape::before { left: 0; }
.tape::after { right: 0; }
.wordmark {
  font-family: 'Permanent Marker', 'Barlow Condensed', cursive;
  font-weight: 400;
  font-size: clamp(30px, 9vw, 44px);
  line-height: 1;
  margin: 0;
  letter-spacing: 0.5px;
}
.subtitle {
  margin: 12px 0 0;
  color: var(--ink-dim);
  font-size: 15px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

/* ---------- Main ---------- */
.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px calc(16px + var(--safe-right)) calc(var(--export-bar-h) + 24px) calc(16px + var(--safe-left));
}

.field { display: block; margin: 8px 0 20px; }
.field__label {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink-dim);
  margin-bottom: 6px;
}
.title-input {
  width: 100%;
  background: var(--panel);
  border: 2px solid var(--line);
  border-bottom-color: var(--tape);
  border-radius: 10px;
  color: var(--ink);
  font-family: 'Permanent Marker', cursive;
  font-size: 24px;
  padding: 12px 14px;
  min-height: 52px;
}
.title-input::placeholder { color: #5c574e; }
.title-input:focus { outline: none; border-color: var(--tape); }

/* ---------- Elements ---------- */
.elements { display: flex; flex-direction: column; gap: 14px; }

.element {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 12px 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.element__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.element__name {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 2px dashed var(--line);
  color: var(--ink);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 22px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 2px;
  min-height: 40px;
}
.element__name:focus { outline: none; border-bottom-color: var(--tape); }
.element__remove {
  flex: none;
  width: 44px; height: 44px;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-size: 22px;
  border-radius: 10px;
  cursor: pointer;
}
.element__remove:active { background: rgba(229, 53, 23, 0.18); color: var(--red); }

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

/* A can swatch = circle + code + name */
.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 74px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  position: relative;
}
.swatch__dot {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 4px solid var(--ring);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.55), inset 0 3px 6px rgba(255, 255, 255, 0.22), inset 0 -6px 10px rgba(0, 0, 0, 0.4);
}
.swatch__code {
  margin-top: 5px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.4px;
  line-height: 1;
}
.swatch__name {
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.05;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  max-width: 74px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* tiny remove dot for a can */
.swatch__x {
  position: absolute;
  top: -6px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #000;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 13px;
  line-height: 20px;
  display: none;
}
.swatch.editing .swatch__x { display: block; }

/* add-can tile */
.swatch--add .swatch__dot {
  border-style: dashed;
  border-color: var(--line);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-dim);
  font-size: 26px;
  box-shadow: none;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  border-radius: 12px;
  min-height: 48px;
  padding: 0 22px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
.btn--ghost {
  width: 100%;
  margin-top: 16px;
  background: transparent;
  color: var(--ink);
  border: 2px dashed var(--line);
}
.btn--ghost:active { border-color: var(--tape); color: var(--tape); }
.btn__plus { font-size: 24px; line-height: 1; }
.btn--export {
  background: var(--tape);
  color: var(--tape-ink);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}
.btn--export:active { transform: translateY(1px); }

.credit {
  margin: 26px 0 0;
  text-align: center;
  color: #6b665d;
  font-size: 12px;
  letter-spacing: 0.4px;
}
.credit a { color: var(--tape); text-decoration: none; }

/* ---------- Fixed export bar ---------- */
.export-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  padding: 10px calc(16px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: linear-gradient(180deg, rgba(12, 12, 12, 0), rgba(12, 12, 12, 0.92) 40%);
  display: flex;
  justify-content: center;
}
.export-bar .btn--export {
  width: 100%;
  max-width: 608px;
  min-height: 54px;
  font-size: 20px;
}

/* ---------- Picker overlay ---------- */
.picker, .export-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(8, 8, 8, 0.98);
  display: flex;
  flex-direction: column;
}
.picker[hidden], .export-view[hidden] { display: none; }

.picker__bar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: calc(10px + var(--safe-top)) calc(12px + var(--safe-right)) 10px calc(12px + var(--safe-left));
  border-bottom: 1px solid var(--line);
  background: var(--wall-2);
}
.picker__search {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 19px;
  letter-spacing: 0.5px;
  padding: 12px 14px;
  min-height: 48px;
}
.picker__search:focus { outline: none; border-color: var(--tape); }
.picker__close {
  flex: none;
  width: 48px; height: 48px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
}
.picker__grid {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px calc(12px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(12px + var(--safe-left));
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 14px 10px;
  align-content: start;
}
.pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
  color: var(--ink);
}
.pick__dot {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 4px solid var(--ring);
  box-shadow: inset 0 3px 6px rgba(255,255,255,0.22), inset 0 -6px 10px rgba(0,0,0,0.4);
}
.pick__code { margin-top: 6px; font-weight: 700; font-size: 13px; }
.pick__name {
  font-size: 11px; color: var(--ink-dim);
  text-transform: uppercase; letter-spacing: 0.2px;
  max-width: 92px; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.picker__empty {
  text-align: center;
  color: var(--ink-dim);
  padding: 40px 20px;
  font-size: 18px;
}

/* ---------- Export view ---------- */
.export-view__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) calc(12px + var(--safe-right)) 10px calc(12px + var(--safe-left));
  border-bottom: 1px solid var(--line);
  background: var(--wall-2);
}
.export-view__hint { flex: 1; color: var(--ink-dim); font-size: 14px; letter-spacing: 0.4px; }
.export-view__scroll {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
}
.export-view__img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  touch-action: manipulation;
}
.export-view__actions {
  display: flex;
  gap: 12px;
  padding: 12px calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  border-top: 1px solid var(--line);
  background: var(--wall-2);
}
.export-view__actions .btn { flex: 1; }

@media (min-width: 560px) {
  .swatch { width: 84px; }
  .picker__grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}
