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

:root {
  --primary: #2e5f3e;
  --primary-dark: #23492f;
  --secondary: #8b5a2b;
  --secondary-dark: #6d4520;
  --accent: #d32f2f;
  --accent-dark: #a52727;
  --felt-light: #3d7a4f;
  --felt-dark: #245038;
  --wood-dark: #4a2f17;
  --wood-light: #c99660;
  --cream: #f4e9d7;
  --ink: #3a2a1a;
}

html, body {
  height: 100%;
}

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.05), transparent 40%),
    repeating-linear-gradient(45deg, rgba(0,0,0,0.06) 0 3px, transparent 3px 6px),
    var(--wood-dark);
  color: var(--cream);
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
}

#app {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.wood-frame {
  position: absolute;
  top: 8px; left: 8px; right: 8px; bottom: 0;
  border: 14px solid;
  border-image: repeating-linear-gradient(
    135deg,
    var(--secondary-dark) 0 10px,
    var(--secondary) 10px 20px,
    var(--secondary-dark) 20px 26px
  ) 14;
  border-radius: 16px 16px 0 0;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.5);
  pointer-events: none;
}

.felt {
  position: absolute;
  top: 22px; left: 22px; right: 22px; bottom: 68px;
  background:
    radial-gradient(circle at 50% 8%, rgba(255,255,255,0.08), transparent 55%),
    radial-gradient(ellipse at center, var(--felt-light), var(--felt-dark) 85%);
  border-radius: 10px;
  box-shadow:
    inset 0 0 40px rgba(0,0,0,0.45),
    inset 0 2px 6px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
}

.felt::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(rgba(255,255,255,0.045) 1px, transparent 1.5px);
  background-size: 9px 9px;
  border-radius: 10px;
  pointer-events: none;
}

.panels {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.panel {
  position: absolute;
  inset: 0;
  padding: 16px 14px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
  flex-direction: column;
}

.panel.active {
  display: flex;
  animation: panelIn 0.28s ease;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  color: var(--cream);
  text-shadow: 0 2px 3px rgba(0,0,0,0.4);
  margin-bottom: 14px;
  letter-spacing: 0.5px;
}

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: absolute;
  left: 10px; right: 10px; bottom: 6px;
  height: 58px;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  padding: 0 6px calc(4px + env(safe-area-inset-bottom));
  z-index: 20;
}

.tab {
  position: relative;
  width: 56px;
  height: 52px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--secondary-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  transition: transform 0.18s ease;
  -webkit-user-select: none;
  user-select: none;
}

.tab .tab-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--wood-dark);
  text-transform: uppercase;
  line-height: 1;
}

.tab .token {
  width: 42px;
  height: 40px;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #c99660, #8b5a2b 60%, #6d4520);
  box-shadow: inset 0 -3px 5px rgba(0,0,0,0.35), inset 0 2px 2px rgba(255,255,255,0.2);
  border-radius: 55% 55% 50% 50% / 100% 100% 45% 45%;
  border: 2px solid rgba(74,47,23,0.6);
}

.tab .token svg {
  width: 20px;
  height: 20px;
  fill: var(--wood-dark);
  filter: drop-shadow(0 1px 0 rgba(255,255,255,0.15));
}

.tab.active {
  transform: translateY(-8px);
}

.tab.active .token {
  background: linear-gradient(160deg, #f05a4a, var(--accent) 45%, var(--accent-dark));
  border-color: #8a1d1d;
  box-shadow:
    inset 0 -4px 6px rgba(0,0,0,0.35),
    0 8px 14px rgba(0,0,0,0.4);
}

.tab.active .token svg {
  fill: #fff;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3));
}

.tab.active .tab-label {
  color: var(--accent-dark);
}

/* ---------- Cards / meeple tokens ---------- */
.meeple-card {
  position: relative;
  width: 100%;
  background: linear-gradient(160deg, var(--wood-light), var(--secondary) 70%);
  border-radius: 60% 60% 55% 55% / 100% 100% 45% 45%;
  border: 2px solid rgba(74,47,23,0.55);
  padding: 20px 14px 14px;
  box-shadow:
    0 6px 12px rgba(0,0,0,0.45),
    inset 0 2px 3px rgba(255,255,255,0.25);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease;
  overflow: hidden;
}

.meeple-card:active {
  transform: scale(0.98);
}

.meeple-card .belly {
  background:
    repeating-linear-gradient(45deg, rgba(90,60,30,0.06) 0 4px, transparent 4px 8px);
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(74,47,23,0.25);
}

.meeple-card .game-name {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 16px;
  color: #3a2410;
  letter-spacing: 0.4px;
  word-break: break-word;
  text-shadow: 0 1px 0 rgba(255,255,255,0.15);
}

.meeple-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.meeple-card .date-wheel {
  font-size: 11px;
  font-weight: 700;
  font-family: "Courier New", monospace;
  background: #f4f0e4;
  border: 1px solid #8a7a5c;
  border-radius: 3px;
  padding: 2px 5px;
  color: #333;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.15);
  letter-spacing: 0.5px;
}

.meeple-card .initials {
  font-size: 12px;
  font-weight: 600;
  color: rgba(58,42,26,0.6);
  letter-spacing: 1px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.2);
  text-transform: uppercase;
}

.meeple-card .delete {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(211,47,47,0.85);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.meeple-card .notes-preview {
  margin-top: 6px;
  font-size: 11px;
  font-style: italic;
  color: rgba(58,42,26,0.7);
  border-top: 1px dashed rgba(74,47,23,0.3);
  padding-top: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Search ---------- */
.search-wrap {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  background: rgba(244,233,215,0.16);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 30px;
  padding: 8px 12px;
}

.search-wrap svg {
  width: 16px;
  height: 16px;
  fill: var(--cream);
  opacity: 0.7;
  margin-right: 8px;
  flex: none;
}

.search-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--cream);
  font-size: 15px;
}

.search-wrap input::placeholder {
  color: rgba(244,233,215,0.6);
}

/* ---------- Buttons ---------- */
.btn-scorecard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background:
    linear-gradient(160deg, #fbf6ea, #efe2c6);
  border: 2px solid rgba(74,47,23,0.5);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
  padding: 12px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(74,47,23,0.55), 0 5px 10px rgba(0,0,0,0.35);
  font-family: Georgia, "Times New Roman", serif;
}

.btn-scorecard:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(74,47,23,0.55);
}

.btn-scorecard svg {
  width: 18px;
  height: 18px;
  fill: var(--secondary-dark);
}

.btn-save {
  width: 100%;
  background: linear-gradient(160deg, #f05a4a, var(--accent) 55%, var(--accent-dark));
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  padding: 13px;
  cursor: pointer;
  box-shadow: 0 3px 0 #7d1c1c, 0 5px 10px rgba(0,0,0,0.35);
  margin-top: 14px;
}

.btn-save:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #7d1c1c;
}

/* ---------- Dashboard dice ---------- */
.dashboard {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.dice-row {
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding: 6px 0 4px;
}

.die {
  width: 88px;
  text-align: center;
}

.die-cube {
  width: 82px;
  height: 82px;
  margin: 0 auto;
  border-radius: 12px;
  background: linear-gradient(145deg, #ffffff, #e4e4e4 60%, #c9c9c9);
  box-shadow:
    inset -4px -6px 10px rgba(0,0,0,0.18),
    inset 4px 4px 6px rgba(255,255,255,0.9),
    0 8px 16px rgba(0,0,0,0.4);
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 14px;
  gap: 2px;
}

.die-cube .pip {
  background: #1c1c1c;
  border-radius: 50%;
  box-shadow: inset 0 2px 2px rgba(0,0,0,0.6);
  align-self: center;
  justify-self: center;
  width: 12px;
  height: 12px;
}

.die-cube[data-pips="1"] .pip:nth-child(-n+4) { display: none; }
.die-cube[data-pips="2"] .pip:nth-child(1),
.die-cube[data-pips="2"] .pip:nth-child(2) { display: block; }
.die-cube[data-pips="3"] .pip:nth-child(1) { display: block; }

.die-cube .pip { display: none; }

.die-label {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--cream);
  opacity: 0.9;
}

.die-count {
  font-family: Georgia, serif;
  font-size: 40px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 3px 4px rgba(0,0,0,0.45);
  line-height: 1;
  margin-bottom: 2px;
}

.die-count-wrap {
  text-align: center;
  margin-bottom: 10px;
}

.die-count-wrap .die-count {
  font-size: 46px;
}

.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: rgba(244,233,215,0.85);
  margin: 14px 0 8px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mini-meeple {
  background: linear-gradient(160deg, var(--wood-light), var(--secondary) 70%);
  border-radius: 55% 55% 50% 50% / 100% 100% 45% 45%;
  border: 2px solid rgba(74,47,23,0.55);
  padding: 10px 12px;
  color: var(--ink);
  box-shadow: 0 4px 8px rgba(0,0,0,0.4);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mini-meeple .m-name {
  font-family: Georgia, serif;
  font-weight: 700;
  font-size: 14px;
}

.mini-meeple .m-sub {
  font-size: 11px;
  color: rgba(58,42,26,0.7);
}

/* ---------- Log form ---------- */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--cream);
  margin-bottom: 6px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.form-group input,
.form-group textarea {
  width: 100%;
  background: rgba(244,233,215,0.92);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--ink);
  outline: none;
}

.form-group textarea {
  min-height: 84px;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(211,47,47,0.25);
}

.error-msg {
  display: none;
  background: rgba(211,47,47,0.15);
  border: 1px solid rgba(211,47,47,0.6);
  color: #ffd0c9;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 10px;
}

.error-msg.show { display: block; }

.autocomplete {
  position: relative;
}

.suggest {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: rgba(244,233,215,0.97);
  border-radius: 0 0 8px 8px;
  box-shadow: 0 6px 12px rgba(0,0,0,0.3);
  overflow: hidden;
  z-index: 30;
  display: none;
}

.suggest.show { display: block; }

.suggest div {
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  border-bottom: 1px solid rgba(74,47,23,0.15);
}

.suggest div:active { background: var(--wood-light); }

.log-actions {
  margin-top: auto;
  padding-top: 10px;
}

.form-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

/* ---------- Games tab ---------- */
.game-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.game-token {
  background: linear-gradient(160deg, var(--wood-light), var(--secondary) 70%);
  border-radius: 8px;
  border: 2px solid rgba(74,47,23,0.5);
  padding: 12px 14px;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0,0,0,0.4);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.game-token .g-name {
  font-family: Georgia, serif;
  font-weight: 700;
  font-size: 15px;
}

.game-token .g-meta {
  font-size: 11px;
  color: rgba(58,42,26,0.7);
  margin-top: 3px;
}

.game-token .g-count {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-dark);
  flex: none;
}

/* ---------- Empty state ---------- */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px 20px;
  color: var(--cream);
  gap: 10px;
}

.empty .big-meeple {
  width: 76px;
  height: 76px;
  background: linear-gradient(160deg, var(--wood-light), var(--secondary) 70%);
  border-radius: 55% 55% 50% 50% / 100% 100% 45% 45%;
  display: grid;
  place-items: center;
  font-family: Georgia, serif;
  font-size: 40px;
  font-weight: 700;
  color: rgba(58,42,26,0.6);
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
}

.empty p {
  font-size: 15px;
  font-family: Georgia, serif;
  max-width: 240px;
  line-height: 1.4;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
