:root{
  /* ===== KKL Brand (Dark default) ===== */
  --bg:#120b07;
  --surface:#1a100b;
  --surface-2:#22160f;
  --text:#fff7e6;
  --muted:#c8b79b;
  --border:rgba(255, 205, 80,.18);
  --shadow: 0 10px 28px rgba(0,0,0,.38);
  --radius:16px;

  --accent:#ffcc33;
  --accent-2:#ffd766;
  --ink:#0b0b0b;
}

*{ box-sizing:border-box; }
html, body{ height:100%; margin:0; }
body{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Noto Sans Thai", sans-serif;
  background:
    radial-gradient(1200px 800px at 20% -10%, rgba(255,204,51,.12), transparent 55%),
    radial-gradient(900px 700px at 90% 10%, rgba(255,215,102,.10), transparent 55%),
    var(--bg);
  color:var(--text);
  min-height:100vh;
  height:100vh;
  display:flex;
  flex-direction:column;
}

/* ===== Top bar ===== */
.topbar{
  display:flex;
  flex-wrap:wrap;
  gap:14px;
  justify-content:space-between;
  align-items:flex-end;
  padding:14px 16px;
  border-bottom:1px solid var(--border);
  background:linear-gradient(180deg, rgba(34,22,15,.92), rgba(26,16,11,.62));
  position:sticky;
  top:0;
  z-index:10;
  backdrop-filter: blur(10px);
}

.brand{
  flex: 1 1 260px;
  min-width: 220px;
}
.brand .title{
  font-weight:800;
  font-size:18px;
  position:relative;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.brand .title::after{
  content:"";
  display:block;
  height:3px;
  width:46px;
  border-radius:999px;
  margin-top:6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity:.9;
}
.brand .subtitle{
  color:var(--muted);
  font-size:12px;
  margin-top:2px;
}

/* (optional) header logo link */
.brand .title a{ white-space:nowrap; display:inline-flex; align-items:center; gap:10px; text-decoration:none; color:inherit; }
.brand .title a img{ height:22px; width:auto; display:block; flex:0 0 auto; }

/* ===== Controls ===== */
.controls{
  flex: 1 1 520px;
  min-width: 280px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:flex-end;
  justify-content:flex-end;
}

.control{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size:12px;
  color:var(--muted);
}

.control input, .control select{
  width:220px;
  max-width:48vw;
  padding:10px 10px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(34,22,15,.72); /* fallback */
  background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  color:var(--text);
  outline:none;
}
.control select{ width:170px; }

.control input:focus-visible, .control select:focus-visible{
  border-color: rgba(255,204,51,.55);
  box-shadow: 0 0 0 4px rgba(255,204,51,.14);
}

.btn{
  height:40px;
  padding:0 14px;
  border-radius:12px;
  border:1px solid var(--border);
  background: rgba(34,22,15,.72); /* fallback */
  background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  color:var(--text);
  cursor:pointer;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease, border-color .12s ease;
  box-shadow: 0 8px 18px rgba(0,0,0,.22);
}
.btn:hover{ filter:brightness(1.10); border-color: rgba(255,204,51,.55); box-shadow: 0 10px 22px rgba(0,0,0,.28); }
.btn:active{ transform: translateY(1px); }

/* ===== Layout (desktop) ===== */
.main{
  flex: 1 1 auto;
  min-height:0;
  display:grid;
  grid-template-columns: 1fr 360px;
  overflow:hidden;
}
#map{ height:100%; width:100%; min-height:0; }

.sidebar{
  height:100%;
  min-height:0;
  border-left:1px solid var(--border);
  background: rgba(26,16,11,.62); /* fallback */
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(10px);
  display:flex;
  flex-direction:column;
  min-width:280px;
  overflow:hidden;
}
.stats{
  padding:12px 14px;
  border-bottom:1px solid var(--border);
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
}
.muted{ color:var(--muted); font-size:12px; }

.list{
  flex: 1 1 auto;
  min-height:0;
  overflow:auto;
  padding:10px;
  display:flex;
  flex-direction:column;
  gap:8px;
}

/* compact cards */
.card{
  background: rgba(34,22,15,.72); /* fallback */
  background: color-mix(in srgb, var(--surface-2) 78%, transparent);
  border:1px solid var(--border);
  border-radius:14px;
  padding:10px;
  box-shadow: var(--shadow);
  cursor:pointer;
}
.card:hover{ filter:brightness(1.06); border-color: rgba(255,204,51,.35); }
.card .name{ font-weight:750; font-size:14px; line-height:1.2; }
.card .meta{
  margin-top:6px;
  font-size:12px;
  color:var(--muted);
  display:flex;
  gap:6px;
  flex-wrap:wrap;
}
.badge{
  font-size:10.5px;
  padding:2px 7px;
  border-radius:999px;
  border:1px solid var(--border);
  color:var(--text);
  background: rgba(0,0,0,.18);
}
.list .card img{ height:86px !important; }

/* ===== Compact search box (prevent overflow) ===== */
.controls .control:first-child{
  flex: 0 1 200px;
  min-width: 160px;
}
#q{
  width: 180px;
  max-width: 42vw;
}
.controls .control input, .controls .control select{ width:100%; }
@media (max-width: 1100px){
  #q{ width: 160px; max-width: 38vw; }
}

/* ===== Light theme ===== */
[data-theme="light"]{
  --bg:#ffffff;
  --surface:#ffffff;
  --surface-2:#fff8e1;
  --text:#0b0b0b;
  --muted:#4b3a2a;
  --border:rgba(75,58,42,.18);
  --shadow: 0 10px 28px rgba(11,11,11,.10);
  --accent:#ffcc33;
  --accent-2:#ffd766;
  --ink:#0b0b0b;
}

/* ===== Mobile ===== */
@media (max-width: 600px){
  .topbar{
    align-items:stretch;
    padding:10px 12px;
    gap:10px;
  }
  .brand .subtitle{ display:none; }
  .brand .title{ font-size:16px; }
  .brand .title::after{ width:34px; margin-top:4px; }
  .brand .title a img{ height:20px; }

  /* Controls: 2 rows, no horizontal scroll */
  .controls{
    display:grid;
    grid-template-columns: 1fr 1fr 44px 44px;
    grid-template-rows: auto auto;
    grid-template-areas:
      "q q q q"
      "type district reset theme";
    gap:8px;
    justify-content:stretch;
    align-items:center;
  }
  .controls > .control:nth-child(1){ grid-area:q; }
  .controls > .control:nth-child(2){ grid-area:type; }
  .controls > .control:nth-child(3){ grid-area:district; }
  .controls > #reset{ grid-area:reset; }
  .controls > #themeToggle{ grid-area:theme; }

  .control span{ display:none; }
  .control input, .control select{
    width:100%;
    max-width:none;
    padding:9px 10px;
    border-radius:12px;
  }
  #reset.btn, #themeToggle.btn{
    padding:0;
    justify-content:center;
  }

  .main{ grid-template-columns: 1fr; }
  #map{ height: 60vh; }
  .sidebar{ height: 40vh; border-left:none; border-top:1px solid var(--border); }
}
.splash{
position:fixed;
inset:0;
background:#120b07;
display:flex;
flex-direction:column;
align-items:center;
justify-content:center;
z-index:9999;
}

.splash img{
width:120px;
height:120px;
margin-bottom:20px;
}

.splash-title{
font-size:20px;
font-weight:700;
color:#ffcc33;
}
