:root {
  --primary: #1e3b5c;
  --accent: #d95d39;
  --secondary: #f2e9d0;
  --grey: #b9bec7;
  --orange: #d95d39;
  --teal: #2f9d8f;
  --ink: #2b3a4a;
  --paper: #e9dcc3;
  --tape: #e6d6ad;
  --grid: rgba(255, 255, 255, 0.16);
  --chrome: linear-gradient(180deg, #e4e6ea 0%, #b9bec6 45%, #8f959e 100%);
  --shadow: 0 8px 22px rgba(10, 20, 35, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #16293f;
  font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", "Marker Felt", cursive;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #16293f;
}

/* ---- Top bar ---- */
.topbar {
  background: #14273b;
  border-bottom: 2px solid #0c1a29;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  text-align: center;
  z-index: 5;
}
.brand {
  margin: 0;
  font-size: 26px;
  letter-spacing: 1px;
  color: var(--secondary);
  font-weight: 700;
}
.brand-sub {
  display: block;
  font-size: 11px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #8fa6bd;
  margin-top: 2px;
}

/* ---- Blueprint sheet ---- */
.blueprint-sheet {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px calc(96px + env(safe-area-inset-bottom));
  background-color: var(--primary);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  border: 10px solid #8a5a2b;
  outline: 2px solid #5c3a1a;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.35);
}

/* ---- Views / tabs ---- */
.view { display: none; }
.view.active { display: block; }

/* ---- Counters ---- */
.counters {
  display: flex;
  gap: 26px;
  justify-content: center;
  align-items: flex-start;
  margin: 8px 0 22px;
  position: relative;
  z-index: 1;
}
.stencil {
  position: relative;
  width: 118px;
  height: 118px;
  border: 8px solid #c8ccd2;
  border-radius: 50%;
  background: linear-gradient(180deg, #d4d7dc, #9aa0a8);
  box-shadow: 0 5px 14px rgba(0,0,0,0.4), inset 0 2px 4px rgba(255,255,255,0.6);
}
.stencil-hole {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 52px;
  font-weight: 700;
  color: var(--secondary);
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.pencil-label {
  display: block;
  font-size: 15px;
  color: var(--secondary);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  opacity: 0.95;
  font-weight: 600;
}
.stencil + .pencil-label { margin-left: 10px; }

/* ---- Section title ---- */
.section-title {
  font-size: 20px;
  color: var(--secondary);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  border-bottom: 2px dashed rgba(255,255,255,0.3);
  padding-bottom: 6px;
  margin: 6px 0 14px;
  font-weight: 700;
}

/* ---- Tape strips ---- */
.tape-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tape {
  position: relative;
  background: var(--tape);
  border-radius: 2px;
  padding: 14px 48px 14px 16px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  cursor: pointer;
  transition: transform 0.12s ease;
}
.tape::before, .tape::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 10px;
  background: inherit;
}
.tape::before {
  left: -8px;
  clip-path: polygon(0 0, 100% 0, 75% 100%, 5% 80%, 20% 60%, 0 45%);
}
.tape::after {
  right: -8px;
  clip-path: polygon(100% 0, 25% 0, 60% 100%, 95% 82%, 100% 55%);
}
.tape:active { transform: scale(0.98); }

.tape-title {
  font-size: 17px;
  font-weight: 700;
  color: #3c3a2f;
  margin: 0 0 4px;
}
.tape-room {
  font-size: 14px;
  color: #6a654f;
  margin: 0;
}

/* paint smear */
.smear {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  width: 14px;
  height: 34px;
  border-radius: 7px;
  box-shadow: inset 0 0 4px rgba(0,0,0,0.25);
}
.smear-grey { background: var(--grey); }
.smear-orange { background: var(--orange); }
.smear-teal { background: var(--teal); }
.lane-head.smear-grey { background: var(--grey); }
.lane-head.smear-orange { background: var(--orange); }
.lane-head.smear-teal { background: var(--teal); }

/* delete affordance */
.tape .delete-hint {
  position: absolute;
  left: 100%;
  top: 0;
  bottom: 0;
  width: 78px;
  background: #c0392b;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  transition: transform 0.2s ease;
  border-radius: 0 2px 2px 0;
}

/* ---- Search ---- */
.search-wrap { margin-bottom: 16px; }
#search-input {
  width: 100%;
  padding: 13px 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  background: rgba(255,255,255,0.12);
  color: var(--secondary);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}
#search-input::placeholder { color: #9fb2c6; }
.empty-note {
  text-align: center;
  color: var(--secondary);
  font-size: 15px;
  opacity: 0.8;
}

/* ---- Floating pencil ---- */
.floating-pencil {
  position: fixed;
  right: 22px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 6;
}
.pencil-icon {
  display: block;
  margin: 0 auto;
  width: 26px;
  height: 26px;
  background: var(--secondary);
  clip-path: polygon(50% 0, 60% 25%, 50% 100%, 40% 25%);
}

/* ---- Form ---- */
.field {
  display: block;
  margin-bottom: 14px;
}
.field .pencil-label {
  font-size: 14px;
  color: var(--secondary);
  margin-bottom: 5px;
  display: block;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 12px;
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  background: rgba(255,255,255,0.13);
  color: var(--secondary);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}
.field textarea { resize: vertical; }
.field select { color: var(--secondary); }
.field select option { color: var(--ink); }
.error {
  display: block;
  color: #ffb3a0;
  font-size: 13px;
  margin-top: 4px;
  min-height: 16px;
}
.field.invalid input, .field.invalid select, .field.invalid textarea {
  border-color: #ff8a70;
}
.btn-primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.btn-ghost {
  padding: 12px 18px;
  border: 2px solid rgba(255,255,255,0.4);
  border-radius: 8px;
  background: transparent;
  color: var(--secondary);
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
}

/* ---- Progress lanes ---- */
.lanes {
  display: flex;
  gap: 10px;
}
.lane {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 240px;
}
.lane-head {
  padding: 8px 4px;
  text-align: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.lane-body {
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}
.lane-card {
  background: var(--tape);
  border-radius: 2px;
  padding: 10px 12px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
  cursor: pointer;
  position: relative;
}
.lane-card::before, .lane-card::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 8px;
  background: inherit;
}
.lane-card::before { left: -6px; clip-path: polygon(0 0, 100% 0, 70% 100%, 10% 80%, 0 50%); }
.lane-card::after { right: -6px; clip-path: polygon(100% 0, 30% 0, 70% 100%, 95% 82%, 100% 50%); }
.lane-card .tape-title { font-size: 13px; }
.lane-card .tape-room { font-size: 11px; }

/* ---- Overlay ---- */
.overlay[hidden] { display: none !important; }
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 16, 28, 0.7);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
.overlay-card {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--secondary);
  border-top: 8px solid #8a5a2b;
  border-radius: 14px 14px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
  max-height: 92dvh;
  overflow-y: auto;
}
.overlay-card .section-title { color: var(--ink); text-shadow: none; border-color: rgba(0,0,0,0.2); }
.overlay-card .field input, .overlay-card .field select,
.overlay-card .field textarea {
  border-color: #c9bfa5;
  background: #fff;
  color: var(--ink);
}
.overlay-card .pencil-label { color: var(--ink); opacity: 0.85; }
.overlay-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.overlay-actions .btn-primary { flex: 1; }
.overlay-actions .btn-ghost { color: var(--ink); border-color: #b9a88a; }

/* ---- Bottom tab bar ---- */
.tabbar {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: 520px;
  display: flex;
  padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
  justify-content: space-around;
  z-index: 15;
}
.tab {
  position: relative;
  border: none;
  background: var(--chrome);
  color: #39404a;
  width: 88px;
  height: 46px;
  border-radius: 4px 4px 10px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}
/* binder clip ring */
.tab::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 10px;
  border: 3px solid #6d737c;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: #aab0b9;
}
.tab.active {
  color: #fff;
  background: linear-gradient(180deg, #f0f2f5 0%, #cdd2d8 50%, #a6acb4 100%);
}
/* tracing paper scrap on active clip */
.tab.active::after {
  content: "";
  position: absolute;
  top: -34px;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  width: 60px;
  height: 34px;
  background: rgba(242, 233, 208, 0.5);
  border-radius: 2px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
  animation: flutter 2.4s ease-in-out infinite;
}
@keyframes flutter {
  0%, 100% { transform: translateX(-50%) rotate(-2deg) translateY(0); }
  50% { transform: translateX(-50%) rotate(-4deg) translateY(-3px); }
}

/* ---- Corner tools ---- */
.corner-tools {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 70px;
  height: 70px;
  pointer-events: none;
  opacity: 0.55;
  z-index: 0;
}
.compass {
  position: absolute;
  width: 46px;
  height: 46px;
  border: 2px solid var(--secondary);
  border-radius: 50%;
  right: 0;
  top: 0;
}
.compass::before {
  content: "";
  position: absolute;
  left: 50%; top: -6px;
  transform: translateX(-50%) rotate(45deg);
  width: 3px; height: 62px;
  background: var(--secondary);
}
.pencil {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 6px;
  height: 40px;
  background: var(--accent);
  transform: rotate(-45deg);
}
.pencil::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: -2px;
  width: 10px;
  height: 12px;
  background: var(--secondary);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

@media (min-width: 521px) {
  .blueprint-sheet { border-width: 14px; }
}