:root {
  --wood: #2b2118;
  --panel: rgba(43, 33, 24, 0.88);
  --parch: #f3e6c8;
  --parch-dim: rgba(243, 230, 200, 0.62);
  --gold: #d9a441;
  --gold-soft: rgba(217, 164, 65, 0.35);
  --good: #8fcf6a;
  --bad: #e5654f;
  --warn: #f0b84a;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a140e;
  color: var(--parch);
  font-family: -apple-system, "Helvetica Neue", "Thonburi", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: 14px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

[hidden] { display: none !important; }

/* ---------- shared panel look ---------- */
.panel, .chip, #speed, #info, #events, #buildbar, #tooltip, #menu, .modal-box, #toast {
  background: var(--panel);
  border: 1px solid var(--gold-soft);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

/* ---------- loading / fatal ---------- */
#loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a140e;
  color: var(--gold);
  font-size: 22px;
  letter-spacing: 0.04em;
  z-index: 100;
  padding: 24px;
  text-align: center;
  line-height: 1.6;
}
#loading.fatal { color: var(--parch); font-size: 18px; }

/* ---------- top bar ---------- */
#topbar {
  position: fixed;
  top: 8px;
  left: 8px;
  right: 260px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  pointer-events: none;
  z-index: 10;
}
.chip {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  min-height: 28px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chip .ic { font-size: 15px; line-height: 1; }
.chip .num { font-weight: 600; }
.chip.gold .num { color: var(--gold); }
.chip.clock { border-color: var(--gold); }
.chip .sub { color: var(--parch-dim); font-weight: 400; font-size: 12px; }
.chip .sick { color: var(--warn); font-weight: 700; }

/* resource groups (วัสดุ / อาหาร / สินค้า) with hover/click popover */
.chip.grp { position: relative; cursor: default; gap: 7px; }
.chip.grp .gl { color: var(--parch-dim); font-size: 12px; }
.chip.grp .hd { display: flex; gap: 8px; }
.chip.grp .h { display: inline-flex; align-items: center; gap: 3px; }
.chip.grp .h.low .num { color: var(--bad); }
.chip.grp .caret { color: var(--parch-dim); font-size: 10px; }
.chip.grp:hover, .chip.grp.open { border-color: var(--gold); }
.gpop {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0;
  padding: 7px 10px 8px;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  z-index: 30;
}
.gpop::before { content: ""; position: absolute; left: 0; right: 0; top: -6px; height: 6px; }
.chip.grp:hover .gpop, .chip.grp.open .gpop { display: block; }
.gpop .gpt { color: var(--gold); font-weight: 700; font-size: 12px; margin-bottom: 3px; }
.gpop .gpg { display: grid; grid-template-columns: 1fr; gap: 1px; }
.gpop .gpi { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.gpop .gpi .ic { width: 20px; text-align: center; }
.gpop .gpi .nm { flex: 1; color: var(--parch-dim); }
.gpop .gpi .num { font-weight: 700; }

/* ---------- speed / menu ---------- */
#speed {
  position: fixed;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 3px;
  padding: 3px;
  z-index: 12;
}
#speed button {
  min-width: 36px;
  height: 28px;
  padding: 0 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
}
#speed button:hover { background: rgba(243, 230, 200, 0.12); }
#speed button.active { background: var(--gold); color: #2b2118; font-weight: 700; }
#speed .sep { width: 1px; background: var(--gold-soft); margin: 3px 2px; }

#menu {
  position: fixed;
  top: 46px;
  right: 8px;
  min-width: 170px;
  padding: 5px;
  z-index: 40;
}
#menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border: 0;
  border-radius: 7px;
}
#menu button:hover { background: rgba(217, 164, 65, 0.22); }

/* ---------- build bar ---------- */
#buildbar {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 540px);
  min-width: 320px;
  padding: 6px;
  z-index: 10;
}
#buildbar .tabs { display: flex; gap: 4px; flex-wrap: wrap; }
#buildbar .tab {
  flex: 1 1 auto;
  padding: 6px 12px;
  background: rgba(243, 230, 200, 0.07);
  border: 1px solid transparent;
  border-radius: 7px;
  white-space: nowrap;
}
#buildbar .tab:hover { background: rgba(243, 230, 200, 0.15); }
#buildbar .tab.open { background: rgba(217, 164, 65, 0.22); border-color: var(--gold-soft); }
#buildbar .tab.has-active { border-color: var(--gold); }
#buildbar .tab.demolish.active { background: rgba(229, 101, 79, 0.45); border-color: var(--bad); }
#buildbar .items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  margin-top: 6px;
  max-height: min(300px, 42vh);
  overflow-y: auto;
  padding-bottom: 2px;
}
#buildbar .items[hidden] { display: none; }
.bbtn {
  flex: 0 0 auto;
  width: 108px;
  padding: 6px 6px 7px;
  text-align: center;
  background: rgba(243, 230, 200, 0.08);
  border: 1px solid rgba(217, 164, 65, 0.25);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.bbtn:hover { background: rgba(217, 164, 65, 0.2); }
.bbtn.active { background: rgba(217, 164, 65, 0.38); border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.bbtn .ic { font-size: 20px; line-height: 1.1; }
.bbtn .nm { font-weight: 600; font-size: 13px; line-height: 1.2; }
.bbtn .cs { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; font-size: 12px; color: var(--parch-dim); min-height: 15px; }
.bbtn .cs .short { color: var(--bad); }
.bbtn .lk { display: none; font-size: 11px; line-height: 1.25; color: var(--warn); }
.bbtn.locked { opacity: 0.55; cursor: not-allowed; }
.bbtn.locked .cs { display: none; }
.bbtn.locked .lk { display: block; }

/* ---------- tooltip ---------- */
#tooltip {
  position: fixed;
  left: 0;
  top: 0;
  max-width: 280px;
  padding: 8px 11px;
  font-size: 13px;
  line-height: 1.45;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.1s;
}
#tooltip.show { opacity: 1; }
#tooltip b { color: var(--gold); }
#tooltip .dim { color: var(--parch-dim); }
#tooltip .warn { color: var(--warn); }

/* ---------- info panel ---------- */
#info {
  position: fixed;
  top: 52px;
  right: 8px;
  width: 270px;
  max-height: calc(100vh - 52px - 190px);
  overflow-y: auto;
  padding: 10px 12px 12px;
  z-index: 11;
  line-height: 1.5;
}
#info .info-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
#info .info-title { font-size: 16px; font-weight: 700; color: var(--gold); }
#info .x {
  width: 26px; height: 26px; padding: 0;
  background: transparent; border: 1px solid var(--gold-soft); border-radius: 6px;
}
#info .x:hover { background: rgba(229, 101, 79, 0.4); }
#info .wrow { display: flex; align-items: center; gap: 8px; margin: 4px 0 6px; }
#info .wrow .wk { min-width: 36px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
#info .wrow button {
  width: 28px; height: 26px; padding: 0; font-weight: 700;
  background: rgba(217, 164, 65, 0.22); border: 1px solid var(--gold-soft); border-radius: 6px;
}
#info .wrow button:hover { background: rgba(217, 164, 65, 0.45); }
#info .stat { font-weight: 600; }
#info .stat.ok { color: var(--good); }
#info .stat.warn, #info .warn { color: var(--warn); }
#info .sub { color: var(--parch-dim); font-size: 12px; margin-top: 7px; }
#info .sub.ok { color: var(--good); }
#info .bar { height: 7px; margin: 4px 0; background: rgba(0, 0, 0, 0.4); border-radius: 4px; overflow: hidden; }
#info .bar i { display: block; height: 100%; background: var(--gold); }
#info .rcs { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 2px; }
#info .rc { white-space: nowrap; font-variant-numeric: tabular-nums; }
#info .rc.short { color: var(--bad); }
#info .small { font-size: 12px; }
#info .ok { color: var(--good); }
#info .dim { color: var(--parch-dim); }
#info .upg { margin-top: 9px; padding: 7px 9px 8px; background: rgba(243, 230, 200, 0.06); border: 1px solid var(--gold-soft); border-radius: 8px; }
#info .upg .uph { color: var(--gold); font-weight: 700; }
#info .upgrow { margin-top: 6px; }
#info .ubtn { width: 100%; padding: 6px 10px; }
#info .ubtn:disabled { opacity: 0.45; cursor: not-allowed; background: rgba(243, 230, 200, 0.1); color: var(--parch); border-color: var(--gold-soft); }
#info .autorow { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
#info .tgl { min-width: 54px; padding: 3px 10px; background: rgba(243, 230, 200, 0.1); border: 1px solid var(--gold-soft); border-radius: 12px; color: var(--parch-dim); }
#info .tgl.on { background: var(--good); color: #1f2a14; border-color: var(--good); font-weight: 700; }
#info ul { list-style: none; margin: 2px 0 0; padding: 0; }
#info li { padding: 1px 0; }
#info li.dim { color: var(--parch-dim); }
#info li.cur { color: var(--gold); font-weight: 600; }

/* ---------- families & villager panel ---------- */
#info .fam li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 5px; padding: 2px 0; }
#info .fam .dim { font-size: 12px; }
#info .si { letter-spacing: 1px; }
#info .gm { color: #7fb8ff; font-weight: 700; }
#info .gf { color: #ff9fc4; font-weight: 700; }
#info .lnk {
  padding: 0; background: none; border: 0; border-bottom: 1px dotted var(--gold-soft);
  color: var(--parch); font: inherit; text-align: left; cursor: pointer; overflow-wrap: anywhere;
}
#info .lnk:hover { color: var(--gold); border-bottom-color: var(--gold); }
#info .chps { display: flex; flex-wrap: wrap; gap: 4px; margin: 5px 0 2px; }
#info .chp {
  padding: 1px 8px; font-size: 12px; border-radius: 10px;
  background: rgba(243, 230, 200, 0.1); border: 1px solid var(--gold-soft);
}
#info .chp.sick { color: var(--warn); border-color: var(--warn); }
#info .chp.pregnant { color: #ffb6d2; border-color: #ffb6d2; }
#info .vrows { margin-top: 6px; }
#info .vr { display: flex; justify-content: space-between; gap: 10px; padding: 1px 0; }
#info .vr > span:last-child { text-align: right; }
#info .rels { display: flex; flex-wrap: wrap; gap: 2px 12px; }

/* ---------- events ---------- */
#events {
  position: fixed;
  right: 8px;
  bottom: 8px;
  width: 250px;
  padding: 6px 10px;
  pointer-events: none;
  z-index: 9;
  font-size: 12.5px;
  line-height: 1.4;
}
#events:empty { display: none; }
#events .ev { padding: 2px 0; transition: opacity 0.3s; white-space: normal; overflow-wrap: anywhere; word-break: break-word; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -8px);
  padding: 9px 18px;
  max-width: 70vw;
  text-align: center;
  font-size: 15px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- modal / help ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 7, 4, 0.55);
  z-index: 80;
  padding: 16px;
}
.modal-box {
  max-width: 440px;
  width: 100%;
  padding: 18px 20px 16px;
  line-height: 1.55;
  -webkit-user-select: text;
  user-select: text;
}
.modal-box h2 { margin: 0 0 8px; color: var(--gold); font-size: 20px; }
.modal-box h3 { margin: 12px 0 4px; font-size: 14px; color: var(--gold); }
.modal-box p { margin: 4px 0; }
.modal-box ol { margin: 4px 0 0; padding-left: 22px; }
.modal-box li { margin: 2px 0; }
.modal-box .ctrls { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 4px 0; }
.modal-box .ctrls b { color: var(--parch); white-space: nowrap; }
.modal-box .ctrls span { color: var(--parch-dim); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.btn {
  padding: 7px 18px;
  background: rgba(243, 230, 200, 0.1);
  border: 1px solid var(--gold-soft);
  border-radius: 8px;
}
.btn:hover { background: rgba(243, 230, 200, 0.2); }
.btn.primary { background: var(--gold); color: #2b2118; font-weight: 700; border-color: var(--gold); }
.btn.primary:hover { background: #e6b55a; }
.btn.danger { background: #a8442f; border-color: #c9573f; }

/* ---------- guide ---------- */
.modal-box.guide { max-width: 860px; height: min(640px, calc(100vh - 32px)); display: flex; flex-direction: column; }
.guide-body { display: flex; gap: 14px; flex: 1; min-height: 0; }
.guide-tabs { display: flex; flex-direction: column; gap: 4px; flex: 0 0 150px; }
.guide-tabs button {
  text-align: left; padding: 7px 10px; border-radius: 8px;
  background: rgba(243, 230, 200, 0.06); border: 1px solid transparent; color: var(--parch-dim);
}
.guide-tabs button:hover { background: rgba(243, 230, 200, 0.14); color: var(--parch); }
.guide-tabs button.active { background: rgba(217, 164, 65, 0.22); border-color: var(--gold-soft); color: var(--parch); font-weight: 700; }
.guide-page { flex: 1; overflow-y: auto; padding-right: 6px; min-width: 0; }
.guide-page h3:first-child { margin-top: 0; }
.guide-page ul, .guide-page ol { margin: 4px 0 8px; padding-left: 22px; }
.guide-page .dim { color: var(--parch-dim); font-size: 0.92em; }
.guide-page .ctrls { grid-template-columns: max-content 1fr; gap: 6px 14px; }
.gt { width: 100%; border-collapse: collapse; margin: 6px 0 8px; font-size: 0.93em; }
.gt th { text-align: left; color: var(--gold); font-weight: 600; border-bottom: 1px solid var(--gold-soft); padding: 4px 6px; }
.gt td { padding: 4px 6px; border-bottom: 1px solid rgba(243, 230, 200, 0.1); vertical-align: top; }
@media (max-width: 700px) {
  .guide-body { flex-direction: column; }
  .guide-tabs { flex-direction: row; flex-wrap: wrap; flex-basis: auto; }
}

/* ---------- narrower windows ---------- */
@media (max-width: 1100px) {
  body { font-size: 13px; }
  #topbar { right: 230px; gap: 4px; }
  .chip { padding: 4px 7px; }
  #events { width: 190px; font-size: 12px; }
  #buildbar { max-width: calc(100vw - 420px); min-width: 280px; }
  .bbtn { width: 94px; }
  #info { width: 240px; }
}
@media (max-width: 800px) {
  #topbar { right: 8px; top: 48px; }
  #events { display: none; }
  #buildbar { max-width: calc(100vw - 16px); }
  #info { top: 96px; max-height: calc(100vh - 96px - 170px); }
}

/* ====================================================================
   Accounts: auth / username / village-select screens (cloud mode)
   ==================================================================== */
.scr {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 24px 16px;
  background: #1a140e;
  -webkit-overflow-scrolling: touch;
}
.scr-bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.scr-scene {
  position: absolute;
  inset: -12px;
  filter: blur(3px) saturate(1.05);
  background: linear-gradient(180deg, #34476b 0%, #8a6f86 38%, #e0a26a 66%, #f0c27f 100%);
  animation: scr-dusk 24s ease-in-out infinite alternate;
}
@keyframes scr-dusk { from { filter: blur(3px) saturate(1.05) hue-rotate(0deg); } to { filter: blur(3px) saturate(1.15) hue-rotate(-14deg); } }
.scr-scene .sun {
  position: absolute; left: 62%; bottom: 36%; width: 120px; height: 120px; border-radius: 50%;
  background: radial-gradient(circle, #fff3c4 0%, rgba(255, 214, 140, 0.85) 38%, rgba(255, 190, 110, 0) 70%);
  animation: scr-sun 16s ease-in-out infinite alternate;
}
@keyframes scr-sun { from { transform: translateY(8px) scale(1); } to { transform: translateY(-18px) scale(1.08); } }
.scr-scene .cl {
  position: absolute; height: 46px; border-radius: 50px; background: rgba(255, 240, 220, 0.5);
  box-shadow: 40px -14px 0 8px rgba(255, 240, 220, 0.45), 90px 2px 0 0 rgba(255, 240, 220, 0.4);
}
.scr-scene .c1 { width: 120px; top: 12%; left: -200px; animation: scr-drift 70s linear infinite; }
.scr-scene .c2 { width: 90px; top: 24%; left: -200px; animation: scr-drift 95s linear -40s infinite; opacity: 0.8; transform: scale(0.8); }
.scr-scene .c3 { width: 150px; top: 6%; left: -200px; animation: scr-drift 120s linear -75s infinite; opacity: 0.6; }
@keyframes scr-drift { from { translate: 0 0; } to { translate: calc(100vw + 500px) 0; } }
.scr-hills { position: absolute; left: 0; bottom: 0; width: 100%; height: 62%; min-height: 260px; }
.scr-hills .h3 { fill: #6d6a7d; }
.scr-hills .h2 { fill: #4f6a47; }
.scr-hills .h1 { fill: #34502f; }
.scr-hills .roofs path { fill: #7a3b2a; }
.scr-hills .roofs rect { fill: #cfae82; }
.scr-scene .fly {
  position: absolute; width: 5px; height: 5px; border-radius: 50%; background: #ffe9a0;
  box-shadow: 0 0 10px 3px rgba(255, 224, 140, 0.7); bottom: 14%;
  animation: scr-fly 7s ease-in-out infinite alternate;
}
.scr-scene .f1 { left: 18%; } .scr-scene .f2 { left: 41%; bottom: 10%; animation-delay: -2s; }
.scr-scene .f3 { left: 72%; bottom: 12%; animation-delay: -4s; } .scr-scene .f4 { left: 88%; animation-delay: -1s; }
@keyframes scr-fly { from { transform: translate(0, 0); opacity: 0.3; } to { transform: translate(22px, -34px); opacity: 1; } }
.scr-veil { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 40%, rgba(26, 20, 14, 0.15) 0%, rgba(26, 20, 14, 0.62) 100%); }
@media (prefers-reduced-motion: reduce) {
  .scr-scene, .scr-scene * { animation: none !important; }
}

.scr-card, .scr-wrap {
  position: relative;
  z-index: 1;
  margin: auto;
  width: 100%;
  -webkit-user-select: text;
  user-select: text;
}
.scr-card {
  max-width: 400px;
  padding: 22px 24px 22px;
  background: var(--panel);
  border: 1px solid var(--gold-soft);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(243, 230, 200, 0.06);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.scr-wrap { max-width: 960px; }
.scr-brand { text-align: center; margin-bottom: 14px; }
.scr-logo { font-size: 38px; line-height: 1.1; }
.scr-brand h1 { margin: 2px 0 0; font-size: 30px; letter-spacing: 0.06em; color: var(--gold); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
.scr-tag { color: var(--parch-dim); font-size: 14px; margin-top: 2px; }
.scr-lead { margin: 0 0 8px; line-height: 1.55; color: var(--parch); }

.scr-tabs { display: flex; gap: 4px; padding: 3px; margin-bottom: 14px; background: rgba(0, 0, 0, 0.28); border-radius: 10px; }
.scr-tab { flex: 1; padding: 8px 6px; background: transparent; border: 1px solid transparent; border-radius: 8px; color: var(--parch-dim); }
.scr-tab:hover:not(:disabled) { color: var(--parch); background: rgba(243, 230, 200, 0.08); }
.scr-tab.active { background: rgba(217, 164, 65, 0.25); border-color: var(--gold-soft); color: var(--parch); font-weight: 700; }

.scr-form { display: flex; flex-direction: column; gap: 10px; }
.scr-field { display: flex; flex-direction: column; gap: 4px; }
.scr-lbl { font-size: 13px; color: var(--parch-dim); }
.scr-hint { font-size: 12px; color: var(--parch-dim); }
.scr input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  font: inherit;
  font-size: 16px;
  color: var(--parch);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--gold-soft);
  border-radius: 8px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.scr input:focus { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(217, 164, 65, 0.25); }
.scr input::placeholder { color: rgba(243, 230, 200, 0.35); }
.scr input:disabled { opacity: 0.55; }
.scr-pw { position: relative; display: block; }
.scr-pw input { padding-right: 64px; }
.scr .scr-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  padding: 4px 10px; font-size: 12px; background: transparent; border: 0; color: var(--parch-dim);
}
.scr .scr-eye:hover:not(:disabled) { color: var(--gold); background: transparent; }

.scr .btn { min-height: 38px; }
.scr .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.scr .btn.primary:disabled { background: var(--gold); }
.scr-submit { width: 100%; min-height: 44px; margin-top: 4px; font-size: 16px; }
.scr-err {
  padding: 8px 11px; font-size: 13.5px; line-height: 1.45; color: #ffd9d1;
  background: rgba(229, 101, 79, 0.2); border: 1px solid var(--bad); border-radius: 8px;
}
.scr-wrap > .scr-err { margin-bottom: 12px; }
.scr-live { min-height: 18px; font-size: 13px; color: var(--parch-dim); }
.scr-live.ok { color: var(--good); }
.scr-live.bad { color: var(--warn); }
.scr-rules { margin: 4px 0 12px; padding-left: 20px; color: var(--parch-dim); font-size: 13.5px; line-height: 1.6; }

.scr-google { margin-top: 14px; }
.scr-or { display: flex; align-items: center; gap: 10px; color: var(--parch-dim); font-size: 12px; margin-bottom: 10px; }
.scr-or::before, .scr-or::after { content: ""; flex: 1; height: 1px; background: var(--gold-soft); }
.scr-gbtn { display: flex; justify-content: center; min-height: 44px; color-scheme: light; }

/* village select */
.scr-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.scr-hello { font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scr-hello b { color: var(--gold); }
.scr .scr-logout { flex: none; min-height: 34px; padding: 5px 14px; }
.scr-title { margin: 6px 0 14px; font-size: 24px; color: var(--parch); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); }
.scr-slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: stretch; }
.scr-slot {
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
  padding: 16px 16px 14px;
  background: var(--panel);
  border: 1px solid var(--gold-soft);
  border-radius: 14px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.scr-slot:hover { border-color: rgba(217, 164, 65, 0.6); }
.scr-slot.empty { border-style: dashed; background: rgba(43, 33, 24, 0.7); justify-content: center; }
.scr-slotno { font-size: 12px; letter-spacing: 0.04em; color: var(--parch-dim); }
.scr-vname { font-size: 20px; font-weight: 700; color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scr-stats { font-size: 14.5px; font-variant-numeric: tabular-nums; }
.scr-last { font-size: 13px; color: var(--parch-dim); margin-bottom: 6px; }
.scr-plus { text-align: center; font-size: 44px; line-height: 1.1; color: var(--gold); opacity: 0.8; margin: 6px 0; }
.scr-slot.empty > .btn { width: 100%; }
.scr-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.scr-slot .scr-btns .btn { padding: 6px 12px; flex: 1 1 auto; }
.scr-slot .scr-btns .btn.primary { flex: 2 1 100%; }
.scr-slot form .scr-btns .btn.primary { flex: 1 1 auto; }
.scr-loading { grid-column: 1 / -1; text-align: center; padding: 40px; color: var(--parch-dim); }
.scr-foot { margin-top: 16px; text-align: center; font-size: 12.5px; color: var(--parch-dim); text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8); }

/* modals */
.scr-modal {
  position: fixed; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(10, 7, 4, 0.62);
}
.scr-mbox {
  width: 100%; max-width: 440px; max-height: 100%; overflow-y: auto;
  padding: 18px 20px 16px;
  background: var(--panel); border: 1px solid var(--gold-soft); border-radius: 12px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.6);
  line-height: 1.55; color: var(--parch);
  -webkit-user-select: text; user-select: text;
}
.scr-mbox h2 { margin: 0 0 8px; color: var(--gold); font-size: 20px; }
.scr-mbox p { margin: 4px 0 10px; }
.scr-mbox .scr-btns { justify-content: flex-end; margin-top: 4px; }
.scr-choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.scr .btn.scr-choice {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 10px 14px; min-height: 56px; width: 100%;
}
.scr .btn.scr-choice span { font-size: 13px; font-weight: 400; opacity: 0.85; }

@media (max-width: 860px) {
  .scr-slots { grid-template-columns: 1fr; max-width: 460px; margin: 0 auto; }
  .scr-wrap { max-width: 460px; }
}
@media (max-width: 420px) {
  .scr { padding: 16px 12px; }
  .scr-card { padding: 18px 16px; }
  .scr-title { font-size: 21px; }
  .scr-slot { padding: 13px 14px 12px; }
}

/* cloud save indicator (under the speed buttons) */
.savestatus {
  position: fixed;
  top: 42px;
  right: 10px;
  z-index: 9;
  padding: 1px 8px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--parch);
  background: rgba(43, 33, 24, 0.9);
  border: 1px solid var(--gold-soft);
  border-radius: 8px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.savestatus[data-kind="error"] { color: #ffd9a0; background: rgba(168, 68, 47, 0.8); }
body.cloud #info { top: 66px; max-height: calc(100vh - 66px - 190px); }
@media (max-width: 800px) {
  body.cloud #topbar { top: 66px; }
  body.cloud #info { top: 114px; max-height: calc(100vh - 114px - 170px); }
}
.scr-foot { display: table; margin-left: auto; margin-right: auto; padding: 3px 12px; background: rgba(43, 33, 24, 0.6); border-radius: 12px; }
