* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #1c3f60;
  --primary-dark: #142f47;
  --secondary: #e6d5b8;
  --accent: #ff6633;
  --grid: rgba(255, 255, 255, 0.14);
  --grid-strong: rgba(255, 255, 255, 0.22);
  --ink: #e6d5b8;
  --chalk: #ffffff;
  --red: #c9321f;
  --card: #b98a54;
  --card-dark: #a57a48;
  --card-light: #cd9f68;
  --nail-red: #d23b2a;
  --nail-yellow: #f2b632;
  --nail-blue: #3a76b8;
  --shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  --pencil-grey: #5b5b5e;
  --pencil-dark: #3f3f42;
}

html, body {
  height: 100%;
}

body {
  font-family: "Indie Flower", "Comic Sans MS", cursive;
  color: var(--ink);
  background: var(--primary);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background:
    radial-gradient(circle at 20% 85%, rgba(0, 0, 0, 0.25), transparent 40%),
    linear-gradient(180deg, var(--primary-dark), var(--primary));
  background-size: 100% 100%;
  position: relative;
  overflow: hidden;
}

/* Blueprint grid overlay */
.app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 26px 26px;
  opacity: 0.9;
}

.app::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(var(--grid-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px);
  background-size: 130px 130px;
  opacity: 0.5;
}

.app-header {
  position: relative;
  z-index: 2;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  position: relative;
  background: transparent;
}

/* spirit level house icon */
.brand-mark::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 16px;
  background: var(--secondary);
  clip-path: polygon(50% 0, 100% 38%, 100% 100%, 0 100%, 0 38%);
}

.brand-mark::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 2px;
  width: 26px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.brand-name {
  font-family: "Architects Daughter", cursive;
  font-size: 24px;
  letter-spacing: 1px;
  color: var(--chalk);
  text-transform: uppercase;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
}

.content {
  position: relative;
  z-index: 2;
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px calc(88px + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

.page-title {
  font-family: "Architects Daughter", cursive;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--chalk);
  font-size: 20px;
  margin: 8px 2px 14px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
}

/* ---------------- Tab bar: carpenter pencils ---------------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  padding: 8px 10px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: rgba(8, 20, 32, 0.9);
  border-top: 2px solid rgba(0, 0, 0, 0.4);
  justify-content: space-between;
  gap: 4px;
}

.pencil {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 46px;
  background: var(--pencil-grey);
  border-radius: 6px 10px 10px 6px;
  border: none;
  cursor: pointer;
  color: var(--ink);
  overflow: visible;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  transition: transform 0.12s ease;
}

.pencil::before {
  /* wood tip */
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 16px;
  background: linear-gradient(180deg, #e0c49b, #c39a68);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.pencil::after {
  /* graphite point */
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  width: 12px;
  height: 4px;
  margin-top: -2px;
  background: #2c2c2e;
  clip-path: polygon(0 50%, 100% 0, 100% 100%);
}

.pencil-label {
  position: relative;
  z-index: 2;
  font-family: "Architects Daughter", cursive;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 95%;
}

.pencil.active {
  background: linear-gradient(180deg, #ff7a45, var(--accent));
  transform: translateY(-3px);
}

.pencil.active::before {
  background: linear-gradient(180deg, #f2d7ac, #d9a86c);
}

.pencil.active .pencil-label {
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

/* ---------------- Cards / tickets ---------------- */
.ticket {
  position: relative;
  background: linear-gradient(180deg, var(--card-light), var(--card));
  color: #4b3418;
  border-radius: 2px 10px 10px 2px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}

/* perforated left edge */
.ticket::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 22px;
  background-image: radial-gradient(circle at 12px 12px, var(--primary) 4px, transparent 4px);
  background-size: 24px 24px;
  background-position: 0 0;
  opacity: 0.85;
}

/* torn right/bottom edge */
.ticket::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 60%;
  height: 18px;
  background: linear-gradient(135deg, transparent 60%, rgba(0, 0, 0, 0.15) 60%);
  opacity: 0.35;
}

.ticket-inner {
  position: relative;
  z-index: 2;
  padding: 12px 14px 12px 30px;
}

.ticket-title {
  font-family: "Architects Daughter", cursive;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 15px;
  color: #3b2a12;
  font-weight: 700;
  padding-right: 34px;
  line-height: 1.2;
}

.ticket-desc {
  font-size: 15px;
  color: #57401f;
  margin-top: 3px;
  line-height: 1.3;
}

.ticket-meta {
  margin-top: 8px;
  font-size: 12px;
  color: #6b5230;
}

/* priority nail head */
.nail {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  z-index: 3;
  box-shadow:
    inset 0 -3px 4px rgba(0, 0, 0, 0.35),
    0 1px 2px rgba(0, 0, 0, 0.4);
}

.nail::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 5px;
  transform: translate(-50%, -50%);
  background: linear-gradient(90deg, rgba(0,0,0,0.35), rgba(255,255,255,0.5), rgba(0,0,0,0.35));
}

.nail-High { background: var(--nail-red); }
.nail-Medium { background: var(--nail-yellow); }
.nail-Low { background: var(--nail-blue); }

/* rubber stamp */
.stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-12deg);
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
  font-size: 26px;
  color: rgba(201, 50, 31, 0.5);
  border: 4px solid rgba(201, 50, 31, 0.5);
  border-radius: 8px;
  padding: 3px 10px;
  letter-spacing: 2px;
  z-index: 4;
  pointer-events: none;
}

.ticket.done {
  background: linear-gradient(180deg, #bfa27e, #ab8a65);
  filter: saturate(0.7);
}

.ticket.done .ticket-inner {
  color: #6b5230;
}

.ticket-btn {
  background: var(--secondary);
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  margin-top: 8px;
  font-family: "Architects Daughter", cursive;
  font-size: 13px;
  color: #4b3418;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

.ticket-btn.delete {
  background: #b03a2c;
  color: #fff;
  margin-left: 6px;
}

/* ---------------- Chalk counters ---------------- */
.chalk-row {
  display: flex;
  gap: 14px;
  margin-bottom: 18px;
}

.chalk-card {
  flex: 1;
  position: relative;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 10px;
}

.chalk-num {
  font-family: "Architects Daughter", cursive;
  color: var(--chalk);
  font-size: 46px;
  line-height: 1;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
}

.chalk-card .chalk-num.red {
  color: #ff8a70;
}

.chalk-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* cardboard scrap backing for open counter */
.scrap {
  background: var(--secondary);
  color: #4b3418;
  border-radius: 8px;
  padding: 12px 8px 10px;
  box-shadow: var(--shadow);
}

.scrap .chalk-num { color: #4b3418; }
.scrap .chalk-label { color: #6b5230; }

/* torn paper corner for completed counter */
.torn {
  background: #d9c3a0;
  color: #4b3418;
  border-radius: 12px 4px 4px 12px;
  padding: 12px 8px 10px;
  box-shadow: var(--shadow);
  clip-path: polygon(0 0, 100% 0, 100% 68%, 92% 76%, 100% 84%, 88% 100%, 0 100%);
}

.torn .chalk-num.red { color: #c9321f; }
.torn .chalk-label { color: #6b5230; }

.section-head {
  font-family: "Architects Daughter", cursive;
  text-transform: uppercase;
  font-size: 15px;
  color: rgba(255, 255, 255, 0.9);
  margin: 6px 2px 10px;
  letter-spacing: 1px;
}

.mini-ticket {
  padding: 9px 12px 9px 26px;
  margin-bottom: 10px;
}

/* ---------------- Search ---------------- */
.search {
  display: block;
  width: 100%;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--chalk);
  font-family: "Indie Flower", cursive;
  font-size: 16px;
  outline: none;
}

.search::placeholder { color: rgba(255, 255, 255, 0.5); }

/* ---------------- Forms ---------------- */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-family: "Architects Daughter", cursive;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 13px;
  color: var(--chalk);
  margin-bottom: 6px;
}

.field {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--chalk);
  font-family: "Indie Flower", cursive;
  font-size: 16px;
  outline: none;
}

.field:focus { border-color: var(--accent); }

select.field {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%),
    linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.suggestion {
  font-family: "Architects Daughter", cursive;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--ink);
  cursor: pointer;
}

.suggestion:active { background: var(--accent); color: #fff; }

.btn {
  font-family: "Architects Daughter", cursive;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.btn.secondary {
  background: var(--secondary);
  color: #4b3418;
  margin-top: 10px;
}

.btn:disabled { opacity: 0.5; }

.error-msg {
  color: #ff9b85;
  font-size: 14px;
  margin-bottom: 10px;
  min-height: 18px;
}

/* ---------------- Modal ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--card-light), var(--card));
  color: #4b3418;
  border-radius: 4px 14px 14px 4px;
  padding: 20px 20px 20px 26px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  font-family: "Architects Daughter", cursive;
  text-transform: uppercase;
  font-size: 18px;
  color: #3b2a12;
  margin-bottom: 14px;
  padding-right: 28px;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-family: "Architects Daughter", cursive;
  font-size: 26px;
  color: #4b3418;
  cursor: pointer;
  line-height: 1;
}

.modal .field {
  background: rgba(255, 255, 255, 0.5);
  color: #3b2a12;
  border-color: rgba(0, 0, 0, 0.15);
}

.modal .error-msg { color: #a12d1e; }

/* ---------------- Confirm ---------------- */
.confirm-text {
  font-size: 17px;
  margin-bottom: 16px;
}

.row {
  display: flex;
  gap: 10px;
}

.row .btn { flex: 1; }

/* ---------------- Empty state ---------------- */
.empty {
  font-family: "Architects Daughter", cursive;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 16px;
  color: #4b3418;
  background: var(--secondary);
  border-radius: 4px 10px 10px 4px;
  padding: 16px 18px 16px 26px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.empty::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 18px;
  background-image: radial-gradient(circle at 9px 9px, var(--primary) 3px, transparent 3px);
  background-size: 18px 18px;
  opacity: 0.4;
}