:root {
  --board: #2e3b2e;
  --board-dark: #1f2a1f;
  --board-light: #3a4a3a;
  --chalk: #f2efe9;
  --chalk-dim: #b9c4b9;
  --yellow: #f4c430;
  --cyan: #43d0c8;
  --magenta: #e26fb0;
  --orange: #f08c3a;
  --red: #e5564a;
  --wood: #7a5230;
  --wood-dark: #5c3c22;
  --wood-light: #9a6a3f;
  --sheet: #2a352a;
}

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

html, body {
  height: 100%;
  background: #141b14;
}

body {
  font-family: "Comic Sans MS", "Segoe Print", "Marker Felt", "Chalkboard SE", "Bradley Hand", "Caveat", cursive, system-ui, sans-serif;
  color: var(--chalk);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }

.chalkboard {
  height: 100vh;
  height: 100dvh;
  background:
    radial-gradient(120% 60% at 20% 10%, rgba(255,255,255,0.03), transparent 60%),
    linear-gradient(180deg, var(--board) 0%, var(--board-dark) 100%);
  position: relative;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
}

/* Dust smudges */
.dust { position: absolute; border-radius: 50%; opacity: 0.05; background: #cfe3cf; filter: blur(10px); pointer-events: none; }
.dust-a { width: 220px; height: 140px; top: 6%; right: -40px; }
.dust-b { width: 180px; height: 120px; top: 38%; left: -60px; }
.dust-c { width: 160px; height: 100px; bottom: 30%; right: 20%; }

/* Top bar */
.topbar {
  padding: 14px 20px 6px;
  text-align: center;
  flex-shrink: 0;
}
.cafe-name { font-size: 20px; letter-spacing: 1px; font-weight: bold; }
.date-line { font-size: 12px; color: var(--chalk-dim); margin-top: 2px; }

/* Content */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px calc(130px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.tab-view { display: none; }
.tab-view.active { display: block; }

.section-title {
  font-size: 15px;
  color: var(--chalk-dim);
  margin: 18px 0 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* Counters */
.counters { display: flex; gap: 12px; }
.counter {
  flex: 1;
  text-align: center;
  padding: 14px 6px 10px;
  position: relative;
}
.counter-num { display: block; font-size: 42px; font-weight: bold; line-height: 1; }
.counter-label { display: block; font-size: 10px; color: var(--chalk-dim); margin-top: 8px; }
.counter-underline {
  display: block;
  width: 70%;
  height: 6px;
  margin: 8px auto 0;
  border-radius: 50%;
  opacity: 0.9;
}
.underline-yellow { background: var(--yellow); }
.underline-cyan { background: var(--cyan); }
.underline-magenta { background: var(--magenta); }

/* Open Table button */
.btn-open {
  width: 100%;
  margin-top: 20px;
  padding: 15px;
  font-size: 18px;
  font-weight: bold;
  color: var(--board-dark);
  background: var(--yellow);
  border: none;
  border-radius: 14px;
  box-shadow: 0 4px 0 #b8901a;
}
.btn-open:active { transform: translateY(2px); box-shadow: 0 2px 0 #b8901a; }

/* Recent activity */
.recent { display: flex; flex-direction: column; gap: 10px; }
.sticky {
  background: rgba(255,255,255,0.04);
  border: 2px dashed var(--chalk-dim);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dot {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
}
.dot-green { background: #8fd18a; box-shadow: 0 0 0 2px rgba(143,209,138,0.3); }
.dot-red { background: var(--red); box-shadow: 0 0 0 2px rgba(229,86,74,0.3); }
.sticky-main { flex: 1; min-width: 0; }
.sticky-table { font-size: 13px; font-weight: bold; }
.sticky-game { font-size: 12px; color: var(--chalk-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sticky-time { font-size: 12px; color: var(--chalk-dim); flex-shrink: 0; }

/* Table map */
.table-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 14px;
  padding: 8px 0;
}
.table-circle {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 32% 30%, var(--wood-light), var(--wood) 60%, var(--wood-dark));
  border: 4px solid var(--red);
  color: #fff;
  box-shadow: inset 0 -6px 10px rgba(0,0,0,0.35), 0 3px 6px rgba(0,0,0,0.3);
  position: relative;
}
.table-circle.available {
  border: 4px dashed #8fd18a;
}
.table-num { font-size: 20px; font-weight: bold; text-shadow: 1px 1px 2px rgba(0,0,0,0.5); }
.table-status { font-size: 9px; letter-spacing: 1px; text-transform: uppercase; opacity: 0.9; }
.tables-empty { color: var(--chalk-dim); text-align: center; margin-top: 30px; font-size: 14px; }

/* Search */
.search-wrap { margin-bottom: 12px; }
.search-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.25);
  color: var(--chalk);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.search-input:focus { border-color: var(--cyan); }

/* Session list */
.session-list { display: flex; flex-direction: column; gap: 12px; }
.session-card {
  background: rgba(255,255,255,0.04);
  border: 2px dashed var(--chalk-dim);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  transition: transform 0.15s;
}
.session-card.swiping { transform: translateX(-72px); }
.session-info { flex: 1; min-width: 0; }
.session-top { display: flex; align-items: center; gap: 8px; }
.session-table { font-size: 14px; font-weight: bold; }
.session-game { font-size: 14px; color: var(--chalk-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { font-size: 11px; color: var(--chalk-dim); margin-top: 4px; }
.swipe-delete {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 72px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 0 12px 12px 0;
  font-weight: bold;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-state { color: var(--chalk-dim); text-align: center; margin-top: 40px; font-size: 14px; }

/* Tools */
.settings-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; color: var(--chalk-dim); text-transform: uppercase; letter-spacing: 1px; }
.text-input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.25);
  color: var(--chalk);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.text-input:focus { border-color: var(--cyan); }
select.text-input { appearance: none; }

.btn-save {
  padding: 13px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: bold;
  color: var(--board-dark);
  background: var(--cyan);
  box-shadow: 0 4px 0 #2e8f88;
}
.btn-save:active { transform: translateY(2px); box-shadow: 0 2px 0 #2e8f88; }

.danger-zone { margin-top: 26px; }
.btn-danger {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  background: var(--red);
  box-shadow: 0 4px 0 #9c372e;
}
.btn-danger:active { transform: translateY(2px); box-shadow: 0 2px 0 #9c372e; }

/* Bottom tray */
.tray {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  background: linear-gradient(180deg, var(--wood-dark), var(--wood-dark) 55%, var(--wood));
  border-top: 3px solid var(--wood-light);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
  box-shadow: 0 -6px 16px rgba(0,0,0,0.4);
}
.chalk {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 74px;
  color: var(--chalk-dim);
  font-size: 10px;
  position: relative;
  transition: transform 0.15s;
}
.chalk-stick {
  width: 22px;
  height: 46px;
  border-radius: 3px;
  position: relative;
  box-shadow: 0 4px 6px rgba(0,0,0,0.35);
  transition: transform 0.15s;
}
.chalk-tip {
  position: absolute;
  top: -1px; left: 0; right: 0;
  height: 8px;
  border-radius: 50% 50% 30% 30%;
  background: rgba(255,255,255,0.35);
}
.chalk-label { letter-spacing: 0.5px; }

.chalk-yellow .chalk-stick { background: var(--yellow); }
.chalk-cyan .chalk-stick { background: var(--cyan); }
.chalk-magenta .chalk-stick { background: var(--magenta); }
.chalk-orange .chalk-stick { background: var(--orange); }

.chalk.active .chalk-stick { transform: translateY(-12px); height: 52px; }
.chalk.active .chalk-tip { height: 10px; background: rgba(255,255,255,0.55); }
.chalk.active { color: #fff; }
.chalk.active .chalk-label { text-shadow: 0 0 6px rgba(255,255,255,0.4); }

/* Bottom sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 30;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  background: var(--sheet);
  border-radius: 18px 18px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  animation: slideUp 0.22s;
  max-height: 88vh;
  overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-grip {
  width: 40px; height: 5px;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  margin: 4px auto 14px;
}
.sheet-title { font-size: 19px; font-weight: bold; margin-bottom: 16px; }
.sheet-form { display: flex; flex-direction: column; gap: 14px; }
.sheet-actions { display: flex; gap: 12px; margin-top: 6px; }
.sheet-actions .btn-save, .sheet-actions .btn-danger, .sheet-actions .btn-ghost { flex: 1; }
.btn-ghost {
  padding: 13px;
  border: 2px solid rgba(255,255,255,0.2);
  background: none;
  color: var(--chalk-dim);
  border-radius: 12px;
  font-size: 14px;
  font-weight: bold;
}
.form-error { color: #ff9d95; font-size: 12px; min-height: 16px; }
.edit-meta { color: var(--chalk-dim); font-size: 12px; }
.detail-body { display: flex; flex-direction: column; gap: 14px; padding-bottom: 6px; }
.detail-row .field-label { display: block; margin-bottom: 4px; }
.detail-row .detail-val { font-size: 18px; font-weight: bold; }
.detail-dot-row { display: flex; align-items: center; gap: 8px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%; bottom: calc(120px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--board-light);
  border: 2px dashed var(--chalk-dim);
  color: var(--chalk);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 80%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }