:root {
  --bg: #f4e9d0;
  --card: #fffaf0;
  --line: #dcc79b;
  --wood: #4a2f17;
  --wood-2: #6b4423;
  --ink: #2b1d0e;
  --muted: #7a6748;
  --gold: #f5b301;
  --blue: #1f7ae0;
  --green: #2e9e4f;
  --red: #c93a2b;
  --radius: 14px;
  --tabs-h: 62px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--blue); }

/* ---------- header ---------- */
.top {
  background: var(--bg);
  border-bottom: 4px solid var(--gold);
  position: sticky;
  top: 0;
  z-index: 10;
}
.top-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 4px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand { display: block; }
.brand img { height: 64px; width: auto; }
@media (min-width: 760px) { .brand img { height: 84px; } }

.banner {
  padding: 10px 14px;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.banner[hidden] { display: none; }
.banner strong {
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: 12px;
  margin-right: 8px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .2);
}
.banner.notice { background: var(--gold); color: #1d1206; }
.banner.alert { background: var(--red); color: #fff; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--wood);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: #999; display: inline-block; }
.dot.on { background: #4be07a; box-shadow: 0 0 6px #4be07a; }
.dot.off { background: var(--red); }

/* ---------- nav: bottom tabs on phones, top bar on wide screens ---------- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  background: var(--wood);
  border-top: 3px solid var(--gold);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1;
  min-height: var(--tabs-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #e9d9b8;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.tabs a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active { color: var(--gold); }
.tabs a.cta { color: #1d1206; background: var(--gold); }

@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .tabs {
    position: static;
    background: var(--wood-2);
    border: 0;
    justify-content: center;
    gap: 4px;
    padding: 0;
  }
  .tabs a { flex: 0 0 auto; flex-direction: row; gap: 8px; min-height: 46px; padding: 0 18px; font-size: 13px; }
}

/* ---------- layout ---------- */
main { max-width: 960px; margin: 0 auto; padding: 16px 12px 32px; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 4px 0 4px; }
h2 { font-size: 1.2rem; margin: 26px 0 10px; }
.lead { color: var(--muted); margin: 0 0 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 0 rgba(74, 47, 23, .06);
}

.hero {
  background: linear-gradient(135deg, var(--wood) 0%, var(--wood-2) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 16px;
  border: 2px solid var(--gold);
}
.hero h1 { color: var(--gold); }
.hero p { margin: 4px 0 12px; color: #f1e4c6; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 13px 20px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  background: var(--gold);
  color: #1d1206;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  min-height: 48px;
}
.btn.secondary { background: #ecdcb6; }
.btn.danger { background: var(--red); color: #fff; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 14px; }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }

.badges { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.badges img { border-radius: 10px; background: #fff; }

/* ---------- announcements ---------- */
.ann.pinned { border-color: var(--gold); border-width: 2px; }
.ann-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.ann h3 { margin: 0; font-size: 1.1rem; }
.ann time { color: var(--muted); font-size: 13px; }
.ann-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0 0; }
.tag {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 8px; border-radius: 999px; background: #e8d9b5; color: var(--wood);
}
.tag.maintenance { background: #ffd9a8; }
.tag.event { background: #cfe8ff; }
.tag.pvp { background: #ffc9c2; }
.tag.update { background: #d3f2d9; }
.tag.pin { background: var(--gold); }

/* ---------- stats + player cards ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 1.35rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; }

.plist { display: grid; gap: 10px; }
@media (min-width: 640px) { .plist { grid-template-columns: 1fr 1fr; } }
.player { display: flex; gap: 12px; align-items: center; }
.lvl {
  flex: 0 0 auto;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--wood); color: var(--gold);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1; border: 2px solid var(--gold);
}
.lvl small { font-size: 9px; letter-spacing: .08em; color: #f1e4c6; }
.lvl b { font-size: 20px; }
.pname { font-weight: 800; font-size: 1.05rem; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { font-size: 12px; background: #efe1bf; border-radius: 8px; padding: 2px 8px; color: var(--wood); }

.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.notice { background: #fff1d6; border: 1px solid var(--gold); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; }

/* ---------- leaderboard ---------- */
.rank { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; }
.pos { font-weight: 900; font-size: 1.2rem; text-align: center; color: var(--muted); }
.rank.r1 .pos { color: #d29a00; }
.rank.r2 .pos { color: #8d9298; }
.rank.r3 .pos { color: #a5642b; }
.hrs { text-align: right; }
.hrs b { font-size: 1.25rem; display: block; line-height: 1.1; }
.hrs span { font-size: 12px; color: var(--muted); }

/* ---------- info ---------- */
.settings-group { margin-bottom: 14px; }
.settings-group h3 { margin: 0 0 6px; font-size: 1rem; color: var(--wood-2); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv span:last-child { font-weight: 700; text-align: right; }

details.faq { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
details.faq summary { cursor: pointer; padding: 13px 14px; font-weight: 700; }
details.faq div { padding: 0 14px 14px; white-space: pre-wrap; }

/* ---------- start here ---------- */
.join-img { border-radius: var(--radius); border: 2px solid var(--wood); margin: 0 auto; max-width: 520px; width: 100%; }
.center { text-align: center; }
.sticky-cta { margin: 16px auto; max-width: 520px; }

dialog {
  border: 0; border-radius: var(--radius); padding: 0;
  width: min(94vw, 460px); max-height: 92vh; overflow: auto;
  background: var(--card); color: var(--ink);
}
dialog::backdrop { background: rgba(30, 18, 6, .6); }
.dlg { padding: 18px 16px; }
.dlg h2 { margin-top: 0; }

label { display: block; font-weight: 700; margin: 12px 0 4px; font-size: 14px; }
input, textarea, select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 140px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.field-err { color: var(--red); font-size: 13px; margin-top: 3px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.hp { position: absolute; left: -9999px; height: 0; overflow: hidden; }
.msg-ok { background: #dff3e4; border: 1px solid var(--green); border-radius: 10px; padding: 12px; }
.msg-err { background: #fde3df; border: 1px solid var(--red); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions .btn { flex: 1; }

footer { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 12px 24px; }
footer a { color: var(--muted); }

body[data-page="admin"] { padding-bottom: env(safe-area-inset-bottom); }
