/* ============ Corkly — Corkboard Traveler's Album ============ */
:root {
  --accent: #c0392b;
  --primary: #5d4a3a;
  --paper: #f2e8d5;
  --paper-dark: #e5d7bd;
  --ink: #3b2f24;
  --wood-dark: #4a3426;
  --wood-light: #7a5636;
  --grey-pin: #4d4d4d;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background-color: var(--paper);
  overflow: hidden;
}

/* ---------- Corkboard background with subtle grain ---------- */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background-color: #b98b52;
  background-image:
    radial-gradient(circle at 18% 22%, rgba(90,60,20,.14) 0 2px, transparent 2.5px),
    radial-gradient(circle at 72% 58%, rgba(90,60,20,.12) 0 2px, transparent 2.5px),
    radial-gradient(circle at 44% 84%, rgba(255,255,255,.10) 0 2px, transparent 2.5px),
    radial-gradient(circle at 88% 16%, rgba(255,255,255,.08) 0 2px, transparent 2.5px),
    radial-gradient(circle at 8% 68%, rgba(90,60,20,.12) 0 2px, transparent 2.5px),
    radial-gradient(circle at 56% 38%, rgba(255,255,255,.07) 0 2px, transparent 2.5px),
    radial-gradient(circle at 30% 48%, rgba(90,60,20,.11) 0 2px, transparent 2.5px),
    radial-gradient(circle at 94% 74%, rgba(255,255,255,.08) 0 2px, transparent 2.5px);
  background-size: 240px 240px, 200px 200px, 190px 190px, 230px 230px, 210px 210px, 220px 220px, 180px 180px, 250px 250px;
}

/* ---------- Panels ---------- */
.tab-panel {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
  padding: 16px;
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}
.tab-panel.active { display: block; }

/* ============ BOARD ============ */
.board-header { display: flex; flex-direction: column; gap: 18px; padding-top: 4px; }

.pins-row { display: flex; gap: 26px; align-items: flex-start; }

.pin-counter { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.pin-btn { position: relative; }

.pin-btn::before {
  content: "";
  position: absolute;
  inset: 4px -2px -2px -2px;
  border-radius: 50%;
  background: rgba(0,0,0,.35);
  filter: blur(5px);
  z-index: 0;
}

.pin-top {
  position: absolute;
  top: -1px; left: 50%;
  transform: translateX(-50%);
  width: 22px; height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #d83a2b, var(--accent) 55%, #7d1f15);
  border: 2px solid #7d1f15;
  box-shadow: 0 3px 5px rgba(0,0,0,.4);
  z-index: 3;
}

.pin-disc {
  position: relative;
  margin-top: 10px;
  width: 74px; height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #f7efe0, var(--paper) 60%, var(--paper-dark));
  border: 4px solid var(--accent);
  box-shadow: 0 5px 10px rgba(0,0,0,.45), inset 0 1px 2px rgba(255,255,255,.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
}

.pin-emboss {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 30px;
  color: var(--accent);
  text-shadow: 0 1px 0 rgba(255,255,255,.6), 0 -1px 1px rgba(0,0,0,.2);
}

.globe-disc .pin-emboss { font-size: 22px; }

.globe-disc::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px solid rgba(192,57,43,.35);
  border-radius: 50%;
}

.pin-label {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #f8ecd8;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  font-weight: 700;
}

/* big cork button */
.cork-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  background: linear-gradient(180deg, #d04937, var(--accent) 55%, #8e2318);
  color: #fff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .5px;
  border: 2px solid #7d1f15;
  border-radius: 26px;
  box-shadow: 0 5px 0 #6b1a12, 0 7px 12px rgba(0,0,0,.4);
  cursor: pointer;
  position: relative;
}
.cork-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #6b1a12, 0 3px 6px rgba(0,0,0,.4); }
.cork-btn-icon { font-size: 20px; }

.board-header .cork-btn { align-self: flex-start; }

/* ============ Recent row ============ */
.recent-wrap { margin-top: 22px; }

.rail-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #f8ecd8;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  margin-bottom: 12px;
  border-bottom: 1px dashed rgba(255,255,255,.35);
  padding-bottom: 6px;
}

.recent-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 10px;
}
.recent-row .stub-card { min-width: 150px; width: 150px; cursor: default; }

.recent-row .stub-card .stub-museum { font-size: 13px; }
.recent-row .stub-card .stub-date { font-size: 10px; }
.recent-row .stub-card .stub-city { font-size: 10px; }

/* ============ Ticket stub (paper) ============ */
.stub-card {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  border-radius: 4px;
  padding: 14px 14px 12px;
  box-shadow: 0 6px 10px rgba(0,0,0,.4), inset 0 0 0 1px rgba(120,90,50,.25);
  clip-path: polygon(0 0, 8px 6px, 12px 0, 20px 6px, 28px 0, 36px 6px, 44px 0, 52px 6px,
    60px 0, 68px 6px, 76px 0, 84px 6px, 92px 0, 100% 0,
    100% calc(100% - 12px), calc(100% - 6px) 100%, 94% calc(100% - 12px),
    88% 100%, 82% calc(100% - 12px), 76% 100%, 70% calc(100% - 12px),
    64% 100%, 58% calc(100% - 12px), 52% 100%, 46% calc(100% - 12px),
    40% 100%, 34% calc(100% - 12px), 28% 100%, 22% calc(100% - 12px),
    16% 100%, 10% calc(100% - 12px), 4% 100%, 0 calc(100% - 12px));
}

.stub-paste {
  height: 14px;
  background: #d8c29a;
  border-radius: 2px;
  margin: -6px -6px 8px;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
}
.stub-paste::before, .stub-paste::after {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: rgba(120,90,50,.6);
}

.stub-museum {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
  padding-right: 42px; /* room for barcode */
}

.stub-date {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 12px;
  letter-spacing: .5px;
  color: #6b5a42;
  margin-top: 6px;
  text-transform: uppercase;
}

.stub-city {
  font-style: italic;
  font-size: 13px;
  color: #8a6f4f;
  margin-top: 2px;
}

.stub-barcode {
  position: absolute;
  bottom: 14px; right: 14px;
  display: flex; align-items: flex-end; gap: 2px;
  height: 20px;
}
.stub-barcode i {
  display: block;
  width: 2px;
  height: 100%;
  background: var(--ink);
}
.stub-barcode i:nth-child(2) { width: 3px; }
.stub-barcode i:nth-child(4) { width: 2px; height: 85%; }
.stub-barcode i:nth-child(6) { width: 3px; height: 92%; }
.stub-barcode i:nth-child(8) { width: 2px; height: 88%; }

.stub-delete {
  position: absolute;
  top: 6px; right: 6px;
  width: 22px; height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  font-weight: 700;
  box-shadow: 0 2px 3px rgba(0,0,0,.3);
  cursor: pointer;
  z-index: 5;
}

/* ============ Stubs list ============ */
.search-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(93,74,58,.92);
  border: 2px solid #3d2f23;
  border-radius: 26px;
  padding: 9px 14px;
  margin-bottom: 14px;
  box-shadow: 0 3px 8px rgba(0,0,0,.4);
}
.search-icon { color: #f8ecd8; font-size: 15px; }
.search-bar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 15px;
}
.search-bar input::placeholder { color: rgba(255,255,255,.6); }

.stub-list { display: flex; flex-direction: column; gap: 16px; }
.stub-list .stub-card { cursor: pointer; }

/* ============ Add form ============ */
.form-shell { padding-top: 4px; }

.form-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  color: #f8ecd8;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  margin-bottom: 16px;
  text-align: center;
}

.ticket-form {
  background: var(--paper);
  border-radius: 6px;
  padding: 22px 16px;
  box-shadow: 0 6px 12px rgba(0,0,0,.4);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 10px),
    calc(100% - 10px) 100%, 0 100%);
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #6b5a42;
  margin-bottom: 6px;
}
.field label em { text-transform: none; font-weight: 400; letter-spacing: 0; color: #9a815f; }
.field input, .field textarea {
  width: 100%;
  border: 2px solid #d3bd96;
  border-radius: 6px;
  background: #faf3e4;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--ink);
  font-family: inherit;
}
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(192,57,43,.25);
}
.field textarea { resize: vertical; min-height: 64px; }
.field.invalid input, .field.invalid textarea { border-color: var(--accent); }
.field .hint { display: none; font-size: 12px; color: var(--accent); margin-top: 4px; }
.field.invalid .hint { display: block; }

.submit-btn { width: 100%; justify-content: center; font-size: 18px; margin-top: 6px; }

/* ============ Cities ============ */
.city-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  padding-top: 4px;
}

.city-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--paper);
  border: 2px solid #c9af83;
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 4px 7px rgba(0,0,0,.35);
  cursor: pointer;
}
.city-name {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.city-badge {
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.25);
}

/* ============ Empty state ============ */
.empty-state { display: none; margin-top: 30px; }
.empty-state.visible { display: block; }

.ticket-placeholder {
  background: var(--paper);
  border-radius: 6px;
  padding: 28px 20px;
  text-align: center;
  color: #7a6545;
  box-shadow: 0 5px 10px rgba(0,0,0,.35);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 12px),
    calc(100% - 12px) 100%, 0 100%);
  position: relative;
}
.ticket-placeholder::before, .ticket-placeholder::after {
  content: "";
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #d9c6a1;
  box-shadow: 0 0 0 1px #c4ab82;
}
.ticket-placeholder::before { left: 16px; top: 16px; }
.ticket-placeholder::after { right: 16px; top: 16px; }
.ticket-placeholder p { font-size: 16px; line-height: 1.4; margin-bottom: 14px; }
.ticket-placeholder .cork-btn { margin: 0 auto; }

/* ============ Bottom rail ============ */
.bottom-rail {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: linear-gradient(180deg, var(--wood-light), var(--wood-dark));
  border-top: 4px solid #3a2719;
  box-shadow: 0 -4px 12px rgba(0,0,0,.5);
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: 2px;
  z-index: 100;
}

.rail-pin {
  position: relative;
  width: 25%;
  height: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 4px;
  -webkit-tap-highlight-color: transparent;
}

.pin-cap {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: block;
  transition: transform .15s ease, background .15s ease;
}

.pin-body {
  width: 6px; height: 14px;
  border-radius: 3px;
  background: linear-gradient(90deg, #2e2e2e, #565656 55%, #1e1e1e);
  transform: translateY(-2px);
  transition: transform .15s ease, background .15s ease;
}

.rail-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  color: #f4e6cf;
  text-shadow: 0 1px 1px rgba(0,0,0,.5);
  margin-top: 2px;
}

/* inactive: pressed flat, matte dark grey */
.rail-pin .pin-cap {
  background: radial-gradient(circle at 35% 30%, #5f5f5f, var(--grey-pin) 60%, #3a3a3a);
  box-shadow: 0 1px 2px rgba(0,0,0,.5), inset 0 -2px 3px rgba(0,0,0,.4);
}

/* active: tilted 15deg, metallic red, soft shadow */
.rail-pin.active .pin-cap {
  background: radial-gradient(circle at 32% 26%, #ef5b47, var(--accent) 55%, #8e2318);
  transform: rotate(15deg) translateY(-6px);
  box-shadow: 0 6px 8px rgba(0,0,0,.4), inset 0 2px 3px rgba(255,255,255,.4);
}
.rail-pin.active .pin-body {
  transform: rotate(15deg) translateY(-8px);
  background: linear-gradient(90deg, #7a1d12, #c0392b 55%, #5c120a);
}

@media (min-width: 480px) {
  .city-grid { grid-template-columns: repeat(3, 1fr); }
}