/* Beasticle Guild Council — Old School RuneScape-inspired interface
   Desktop (≥ 900px): votes on the left, coin pouch + online clan on the right, chat docked at the bottom.
   Phone   (< 900px): one column with a bottom tab bar (Votes · Chat · Clan · Archive · Settings). */

:root {
  --void:        #0e0c0a;
  --stone-dark:  #2a241d;
  --stone:       #3e3529;
  --stone-mid:   #4a4033;
  --stone-light: #5c5242;
  --edge-light:  #75684f;
  --edge-dark:   #15120e;

  --orange: #ff981f;   /* standard interface text */
  --yellow: #ffff00;   /* highlights / you */
  --gold:   #ffb83f;
  --white:  #ffffff;
  --beige:  #d8c9a3;
  --muted:  #b8a888;
  --green:  #0dc10d;
  --red:    #e02a2a;
  --hp-green: #078a07;
  --hp-red:   #8a0b0b;
  /* options 3 and 4 */
  --opt3: #4fc3ff;  --opt3-bar: #1d5f9a;
  --opt4: #d68cff;  --opt4-bar: #6b2f8a;

  --parchment: #d4c39a;
  --ink:       #1b1408;
  --ink-blue:  #0000c8;

  --font: 'Pixelify Sans', 'Courier New', ui-monospace, monospace;
  --shadow: 1px 1px 0 #000;

  --dock-h: 230px;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);

  /* Subtle stone grain, generated (no image assets). */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  /* A little stack of gold coins. */
  --coin: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cellipse cx='8' cy='12.2' rx='6.2' ry='2.6' fill='%237a5c00' stroke='%23000'/%3E%3Cellipse cx='8' cy='9.6' rx='6.2' ry='2.6' fill='%23c79a00' stroke='%23000'/%3E%3Cellipse cx='8' cy='7' rx='6.2' ry='2.6' fill='%23ffd21f' stroke='%23000'/%3E%3Cellipse cx='7' cy='6.4' rx='2.4' ry='.8' fill='%23fff3a0'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  background-color: var(--void);
  background-image: var(--grain), radial-gradient(ellipse at top, #231d16 0%, var(--void) 70%);
  color: var(--orange);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  text-shadow: var(--shadow);
  font-variant-ligatures: none; /* Pixelify joins "fi" into one glyph */
  font-feature-settings: "liga" 0, "clig" 0;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.frame {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
}

h1, h2, h3 { margin: 0; font-weight: 500; letter-spacing: .5px; }
h1 { font-size: 26px; color: var(--orange); text-transform: uppercase; }
h2 { font-size: 18px; color: var(--orange); margin-bottom: 8px; }

.muted   { color: var(--muted); }
.hint    { color: var(--beige); font-size: 14px; margin: 0 0 10px; }
.center  { text-align: center; }
.small   { font-size: 13px; }
.error   { color: var(--red); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }
.me-inline { color: var(--yellow); }
.empty   { color: var(--muted); font-size: 14px; margin: 0; }

/* --- Stone panels ------------------------------------------------------- */

.panel {
  position: relative;
  background-color: var(--stone);
  background-image: var(--grain);
  border: 2px solid var(--edge-dark);
  box-shadow:
    inset 0 0 0 2px var(--stone-light),
    inset 0 0 0 3px var(--edge-dark),
    inset 2px 2px 0 3px var(--edge-light),
    0 2px 0 #000;
  padding: 12px 14px;
  margin-bottom: 12px;
}
/* little rivets in the corners, like OSRS frames */
.panel::before, .panel::after {
  content: '';
  position: absolute;
  top: 4px;
  width: 4px; height: 4px;
  background: #8c7b5a;
  box-shadow: 0 0 0 1px #000;
}
.panel::before { left: 4px; }
.panel::after  { right: 4px; }

/* --- Header ------------------------------------------------------------- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.subtitle { margin: 2px 0 0; color: var(--yellow); font-size: 15px; }
.whoami { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.me-name { color: var(--yellow); }

.me-button {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px solid transparent; padding: 2px 4px;
  font: inherit; color: inherit; text-shadow: inherit; cursor: pointer;
  min-height: 36px;
}
.me-button:hover { border-color: var(--edge-light); background: var(--stone-mid); }

.gp-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font: inherit; font-size: 15px; color: var(--yellow); text-shadow: var(--shadow);
  background: var(--stone-dark); border: 1px solid #000;
  box-shadow: inset 1px 1px 0 #000, inset -1px -1px 0 var(--stone-light);
  padding: 3px 8px; min-height: 32px; cursor: pointer;
}
.gp-pill:hover { background: var(--stone-mid); }

/* --- Coins -------------------------------------------------------------- */

.coin {
  display: inline-block; flex: none;
  width: 16px; height: 16px;
  background: var(--coin) center / contain no-repeat;
  vertical-align: -3px;
}
.coin-lg { width: 30px; height: 30px; }
.coin.spent { opacity: .2; filter: grayscale(1); }

/* --- Buttons ------------------------------------------------------------ */

.btn, .tab {
  font: inherit;
  color: var(--orange);
  text-shadow: var(--shadow);
  background: var(--stone-mid);
  border: 1px solid var(--edge-dark);
  box-shadow: inset 1px 1px 0 var(--edge-light), inset -1px -1px 0 #221d17;
  padding: 5px 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.btn:hover, .tab:hover { color: var(--white); background: var(--stone-light); }
.btn:active, .tab:active { box-shadow: inset -1px -1px 0 var(--edge-light), inset 1px 1px 0 #221d17; }
.btn:focus-visible, .tab:focus-visible, .linkish:focus-visible, .column:focus-visible, .gp-pill:focus-visible {
  outline: 1px solid var(--yellow); outline-offset: 1px;
}
.btn:disabled { color: #8a7c62; cursor: default; background: var(--stone); }
.btn:disabled:hover { color: #8a7c62; background: var(--stone); }
.btn-small { font-size: 13px; padding: 2px 8px; min-height: 26px; }
.btn-wide  { width: 100%; margin-top: 4px; min-height: 40px; }
.btn-danger { color: #ff6b5a; }
.btn-danger:hover { color: #fff; background: #5a2620; }

.linkish {
  background: none; border: 0; font: inherit; color: var(--muted);
  text-decoration: underline; cursor: pointer; text-shadow: var(--shadow);
}
.linkish:hover { color: var(--yellow); }

/* --- Layout ------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  grid-template-areas: "tabs side" "main side";
  grid-template-rows: auto 1fr;
  column-gap: 12px;
}
.tabs    { grid-area: tabs; }
.main    { grid-area: main; min-width: 0; }
.sidebar {
  grid-area: side;
  position: sticky; top: 12px; align-self: start;
  max-height: calc(100vh - var(--dock-h) - 24px);
  overflow-y: auto;
}
body.dock-collapsed .sidebar { max-height: calc(100vh - 60px); }

/* --- Tabs --------------------------------------------------------------- */

.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab {
  flex: 1; padding: 8px 6px; font-size: 15px; background: var(--stone);
  display: flex; align-items: center; justify-content: center; gap: 6px; position: relative;
}
.tab-icon { color: var(--gold); }
.tab[aria-selected="true"] {
  color: var(--yellow);
  background: #5a2b1e;
  box-shadow: inset 1px 1px 0 #8a4a33, inset -1px -1px 0 #2a120c;
}
.mobile-only { display: none; }

/* --- Forms -------------------------------------------------------------- */

input, textarea {
  font: inherit;
  font-size: 16px; /* 16px+ stops iOS zooming in on focus */
  color: var(--white);
  text-shadow: var(--shadow);
  background: var(--stone-dark);
  border: 1px solid var(--edge-dark);
  border-radius: 0;
  box-shadow: inset 1px 1px 0 #000, inset -1px -1px 0 var(--stone-light);
  padding: 7px 8px;
  width: 100%;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, textarea:focus { outline: 1px solid var(--orange); }
input::placeholder, textarea::placeholder { color: #8a7c62; }
/* Multiline vote text; app.js grows the box to fit what's typed. */
textarea { display: block; resize: none; overflow: hidden; line-height: 1.35; min-height: 38px; white-space: pre-wrap; overflow-wrap: anywhere; }
input[type="color"] {
  width: 52px; height: 36px; padding: 2px; flex: none; cursor: pointer;
  -webkit-appearance: auto; appearance: auto;
}
input[type="checkbox"] { width: 18px; height: 18px; padding: 0; flex: none; -webkit-appearance: auto; appearance: auto; accent-color: var(--orange); }
.check-row { display: flex; align-items: center; gap: 8px; color: var(--beige); font-size: 15px; cursor: pointer; }

.field { display: block; margin-bottom: 10px; }
.field span { display: block; color: var(--beige); font-size: 14px; margin-bottom: 3px; }
.stack > * + * { margin-top: 8px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
.inline-form { display: flex; gap: 8px; }
.inline-form .btn { flex: none; }

.login { max-width: 400px; margin: 40px auto; }

/* --- New vote form ------------------------------------------------------ */

.new-vote > summary {
  cursor: pointer; color: var(--orange); font-size: 18px;
  list-style: none; user-select: none; -webkit-user-select: none;
}
.new-vote > summary::-webkit-details-marker { display: none; }
.new-vote > summary::before { content: '+ '; color: var(--yellow); }
.new-vote[open] > summary::before { content: '− '; }
.new-vote[open] > summary { margin-bottom: 10px; }

.picture-picker { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.topic-image-preview { max-width: 220px; max-height: 160px; border: 1px solid #000; display: block; }

.option-inputs > * + * { margin-top: 6px; }
.option-input { display: flex; align-items: flex-start; gap: 6px; }
.option-input .opt-n { flex: none; width: 20px; padding-top: 8px; color: var(--muted); text-align: right; }
.option-input textarea { flex: 1; }
.option-input .btn { flex: none; min-height: 38px; }
.option-input[data-index="0"] .opt-n { color: var(--green); }
.option-input[data-index="1"] .opt-n { color: var(--red); }
.option-input[data-index="2"] .opt-n { color: var(--opt3); }
.option-input[data-index="3"] .opt-n { color: var(--opt4); }
.add-option { margin-top: 6px; }

/* --- Votes -------------------------------------------------------------- */

.topic { scroll-margin-top: 12px; }
.topic.flash { animation: flash 1s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--yellow); } }

.topic-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.topic-head h2 { overflow-wrap: anywhere; white-space: pre-wrap; min-width: 0; }
.topic-meta { color: var(--muted); font-size: 13px; margin: -4px 0 6px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.topic-actions { display: flex; gap: 4px; flex: none; }
.badge { font-size: 12px; padding: 1px 6px; color: var(--red); border: 1px solid #000; background: var(--stone-dark); }

.topic-image {
  display: block; max-width: 100%; max-height: 240px; margin: 4px auto 10px;
  border: 2px solid #000; box-shadow: 0 0 0 1px var(--edge-light);
  cursor: zoom-in;
}

.bar {
  display: flex; height: 14px; margin: 4px 0 10px;
  border: 1px solid #000; background: var(--stone-dark);
}
.bar > div { height: 100%; transition: width .25s ease; box-shadow: inset 0 2px 0 rgba(255,255,255,.15); }
.bar .seg-0 { background: var(--hp-green); }
.bar .seg-1 { background: var(--hp-red); }
.bar .seg-2 { background: var(--opt3-bar); }
.bar .seg-3 { background: var(--opt4-bar); }
.bar-labels { display: flex; justify-content: center; gap: 6px; font-size: 13px; color: var(--beige); }
.bar-labels .gp { color: var(--yellow); }

.columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.column {
  background: var(--stone-dark);
  border: 1px solid #000;
  box-shadow: inset 1px 1px 0 #000, inset -1px -1px 0 var(--stone-light);
  min-height: 110px;
  padding: 6px;
  cursor: pointer;
  min-width: 0;
  transition: background-color .1s;
  touch-action: manipulation;
}
.column-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 6px;
  border-bottom: 1px solid #000; box-shadow: 0 1px 0 var(--stone-light);
  padding-bottom: 4px; margin-bottom: 6px;
}
/* Long option text wraps onto as many lines as it needs; the tallies drop below it. */
.column-head .label { flex: 1 1 auto; overflow-wrap: anywhere; white-space: pre-wrap; min-width: 0; }
.column-head .tallies { flex: none; margin-left: auto; white-space: nowrap; }
.column-head .pct { color: var(--beige); font-size: 13px; }
.column[data-index="0"] .column-head .label, .opt-name[data-index="0"] { color: var(--green); }
.column[data-index="1"] .column-head .label, .opt-name[data-index="1"] { color: var(--red); }
.column[data-index="2"] .column-head .label, .opt-name[data-index="2"] { color: var(--opt3); }
.column[data-index="3"] .column-head .label, .opt-name[data-index="3"] { color: var(--opt4); }
.column .tally { color: var(--yellow); white-space: nowrap; display: inline-flex; align-items: center; gap: 3px; }
.column .voters-n { color: var(--muted); font-size: 12px; }
.column:hover, .column.drop-hover, .tray.drop-hover { background-color: #3a3127; }
.column.drop-hover, .tray.drop-hover { outline: 1px solid var(--yellow); }
.column.mine { box-shadow: inset 0 0 0 1px var(--gold); }
.closed .column, .archived .column { cursor: default; }
.closed .column:hover, .archived .column:hover { background-color: var(--stone-dark); }
.winner { color: var(--gold); }

.plates { display: flex; flex-wrap: wrap; gap: 4px; align-content: flex-start; }

/* Nameplates — small inventory-item-like tags */
.plate {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 14px;
  color: var(--white);
  background: #2e2820;
  border: 1px solid #000;
  box-shadow: inset 1px 1px 0 #4a4033, inset -1px -1px 0 #171310;
  padding: 2px 6px 2px 3px;
  white-space: nowrap;
  max-width: 100%;
  min-height: 26px;
}
.plate .plate-name { overflow: hidden; text-overflow: ellipsis; }
.plate.deleted .plate-name { color: var(--muted); font-style: italic; }
.plate .stake { display: inline-flex; align-items: center; gap: 2px; color: var(--yellow); font-size: 12px; }
.plate .stake .coin { width: 12px; height: 12px; vertical-align: 0; }
.plate-remove {
  border: 0; padding: 0 2px; background: transparent; color: var(--muted);
  font: inherit; line-height: 1; cursor: pointer; touch-action: manipulation;
}
.plate-remove:hover { color: var(--red); }
.plate.me {
  color: var(--yellow);
  border-color: var(--gold);
  background: #4a3a1a;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.plate.me:hover { background: #5c4820; }
.closed .plate.me, .archived .plate.me { cursor: default; touch-action: auto; }
.plate.ghost {
  position: fixed; z-index: 100; pointer-events: none;
  cursor: grabbing; opacity: .92;
  transform: translate(-50%, -50%) rotate(-2deg) scale(1.1);
  box-shadow: 2px 2px 0 #000;
}
.plate.lifted { opacity: .35; }

/* "Your gold" strip under each vote: drag source when undecided, stake controls once voted */
.tray {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 8px; padding: 6px;
  background: var(--stone-dark);
  border: 1px dashed #6b5e47;
  min-height: 44px;
}
.tray-label { color: var(--muted); font-size: 13px; }
.tray-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%; }
.stake-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; width: 100%; }
.stake-controls + .stake-controls, .tray-row + .stake-controls { border-top: 1px solid #000; box-shadow: inset 0 1px 0 var(--stone-mid); padding-top: 6px; }
.stake-controls .on { flex: 1 1 120px; min-width: 0; }
/* Which option a stake is on; long option text is shortened here (it's shown in full above). */
.stake-controls .opt-name {
  display: -webkit-inline-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  overflow: hidden; overflow-wrap: anywhere; vertical-align: top;
}
.stake-controls .amount {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--yellow); min-width: 64px; justify-content: center;
}
.stake-btn { width: 36px; min-height: 32px; padding: 0; font-size: 18px; line-height: 1; }
.stake-controls .on { color: var(--beige); font-size: 13px; }
.stake-controls .withdraw { margin-left: auto; }

/* --- Sidebar: coin pouch + clan ----------------------------------------- */

.pouch-total { display: flex; align-items: center; gap: 8px; font-size: 22px; color: var(--yellow); }
.pouch-total .of { font-size: 14px; color: var(--beige); }
.pouch-coins { display: flex; flex-wrap: wrap; gap: 2px; margin: 8px 0; }
.pouch-coins .coin { width: 20px; height: 20px; }
.stake-list { list-style: none; margin: 6px 0 0; padding: 0; }
.stake-list li + li { border-top: 1px solid #000; box-shadow: inset 0 1px 0 var(--stone-mid); }
.stake-list button {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: none; border: 0; padding: 6px 2px; cursor: pointer; text-align: left;
  font: inherit; font-size: 14px; color: var(--white); text-shadow: var(--shadow);
}
.stake-list button:hover { color: var(--yellow); }
.stake-list .t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.stake-list .tt, .stake-list .side {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.stake-list .side { color: var(--muted); font-size: 12px; }
.stake-list .n { color: var(--yellow); white-space: nowrap; display: inline-flex; align-items: center; gap: 3px; }

.clan h2 { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.clan-list { list-style: none; margin: 0; padding: 0; }
.clan-list li { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; padding: 5px 0; font-size: 15px; color: var(--white); }
.clan-list li + li { border-top: 1px solid rgba(0,0,0,.5); }
.clan-list li.me { color: var(--yellow); }
.clan-list li.offline > .avatar { opacity: .55; }
.clan-list li.offline .uname { opacity: .75; }
/* Name, then the role right after it; long roles wrap instead of being cut off. */
.ident { flex: 1 1 110px; min-width: 0; overflow-wrap: anywhere; }
.ident .dot { margin-right: 4px; vertical-align: 1px; }
.clan-list .rank-star { color: var(--gold); font-size: 12px; }
.member-side { display: flex; align-items: center; gap: 4px; margin-left: auto; flex: none; }
.clan-list .gp-left { color: var(--yellow); font-size: 13px; display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.clan-list .gp-left .coin { width: 13px; height: 13px; vertical-align: 0; }
.clan-list .member-side .btn { flex: none; min-height: 28px; padding: 2px 6px; }

/* Player names in their chosen colour, with their free-text role beside them */
.role { color: var(--beige); font-size: 12px; margin-left: 5px; }
.role::before { content: '— '; color: var(--muted); }
.gold-who { margin: 0; color: var(--white); overflow-wrap: anywhere; }
.gold-who .gp { color: var(--yellow); }

/* --- Avatars ------------------------------------------------------------ */

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
  width: 18px; height: 18px;
  border: 1px solid #000;
  background: var(--av, #5c5242);
  color: #fff; font-size: 11px; line-height: 1;
  text-shadow: var(--shadow);
  overflow: hidden;
  vertical-align: middle;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.lg { width: 28px; height: 28px; font-size: 15px; }
.clan-list .avatar { width: 24px; height: 24px; font-size: 13px; }
.profile-row { display: flex; gap: 14px; align-items: center; }

/* --- Settings ----------------------------------------------------------- */

.gear-btn { font-size: 17px; min-width: 32px; line-height: 1; }
.gear-btn[aria-pressed="true"] { color: var(--yellow); background: #5a2b1e; }
.settings { max-width: 560px; }
.settings-preview {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px; padding: 8px;
  background: var(--stone-dark); border: 1px solid #000; font-size: 17px; color: var(--yellow);
}
.color-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.profile-avatar .avatar { width: 96px; height: 96px; font-size: 44px; border: 2px solid #000; box-shadow: 0 0 0 1px var(--edge-light); }

/* --- Admin -------------------------------------------------------------- */

.admin-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-wrap: wrap;
  padding: 6px 0;
  border-bottom: 1px solid #000;
  box-shadow: 0 1px 0 var(--stone-mid);
}
.admin-item:last-child { border-bottom: 0; box-shadow: none; }
.admin-item .label { color: var(--white); overflow-wrap: anywhere; white-space: pre-wrap; }
.admin-item > span:first-child { min-width: 0; flex: 1 1 200px; }
.admin-item .meta  { display: block; color: var(--beige); font-size: 13px; }
.admin-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border: 1px solid #000; background: #555; }
.dot.on { background: var(--green); }
.tag { font-size: 12px; color: var(--gold); margin-left: 4px; }

/* --- Dialogs ------------------------------------------------------------ */

.dialog { color: var(--orange); width: min(440px, calc(100vw - 32px)); margin: auto; max-height: calc(100dvh - 32px); overflow-y: auto; }
.dialog-wide { width: min(620px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }

/* --- Toast -------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  z-index: 200;
  width: min(520px, calc(100vw - 32px));
  background: var(--parchment);
  border: 2px solid #3b3022;
  box-shadow: inset 0 0 0 1px #9c8a62, 0 2px 0 #000;
  padding: 8px 10px;
  color: var(--ink);
  text-shadow: none;
  font-size: 15px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast .who { color: var(--ink-blue); }
.toast.err  { color: #8a0000; }

.footer { text-align: center; padding: 8px 0; font-size: 13px; }

/* --- Chat dock (desktop) ------------------------------------------------ */

body.has-dock { padding-bottom: calc(var(--dock-h) + 10px); }
body.has-dock.dock-collapsed { padding-bottom: 50px; }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-width: var(--dock-w, 1176px); margin: 0 auto;
  background-color: var(--stone);
  background-image: var(--grain);
  border: 2px solid var(--edge-dark);
  border-bottom: 0;
  box-shadow: inset 0 0 0 2px var(--stone-light), inset 0 0 0 3px var(--edge-dark), 0 -2px 0 #000;
  padding: 4px 6px 6px;
  padding-bottom: calc(6px + var(--safe-b));
}
.dock-bar {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: 0; padding: 2px 4px 4px;
  font: inherit; color: var(--orange); text-shadow: var(--shadow);
  cursor: pointer; text-align: left;
}
.dock-bar:hover { color: var(--white); }
.dock-caret { margin-left: auto; transition: transform .15s; }
.dock.collapsed .dock-caret { transform: rotate(180deg); }
.dock.collapsed .dock-body { display: none; }
.unread { background: var(--red); color: #fff; font-size: 11px; padding: 0 5px; border: 1px solid #000; line-height: 1.4; }
.tab .unread { position: absolute; top: 3px; right: 6px; }

.dock-body { height: calc(var(--dock-h) - 34px); }

.chat {
  display: flex; flex-direction: column; min-width: 0; height: 100%;
  background: var(--parchment);
  border: 2px solid #3b3022;
  box-shadow: inset 0 0 0 1px #9c8a62;
  text-shadow: none;
}
.chat-log {
  list-style: none; margin: 0; padding: 4px 8px;
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  font-size: 14px; color: var(--ink);
}
.chat-line { display: flex; gap: 5px; align-items: flex-start; padding: 1px 0; }
.chat-line .avatar { width: 16px; height: 16px; font-size: 10px; margin-top: 1px; }
.chat-line .time { color: #6b5a3a; font-size: 12px; flex: none; padding-top: 1px; }
.chat-line .body { overflow-wrap: anywhere; min-width: 0; }
.chat-line .who { color: var(--ink); }
.chat-line .text { color: var(--ink-blue); }
.chat-line.mine .who { color: #5a0000; }
.chat-line.system .text { color: #5a2d00; }
.chat-line .del {
  margin-left: auto; flex: none; visibility: hidden;
  background: none; border: 0; color: #8a0000; cursor: pointer; font: inherit; font-size: 12px; padding: 0 2px;
}
.chat-line:hover .del, .chat-line .del:focus-visible { visibility: visible; }

.chat-form {
  display: flex; align-items: center; gap: 6px;
  border-top: 1px solid #9c8a62; padding: 3px 6px 3px 8px;
}
.chat-prompt { flex: none; color: var(--ink); white-space: nowrap; font-size: 14px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.chat-prompt::after { content: ':'; }
.chat-form input {
  flex: 1; width: auto;
  background: transparent; border: 0; box-shadow: none; padding: 4px 0;
  color: var(--ink-blue); text-shadow: none;
}
.chat-form input:focus { outline: none; }
.chat-form input::placeholder { color: #8a7a55; }
.chat-send { flex: none; }
.chat { position: relative; }
.cmd-btn { flex: none; min-width: 30px; padding: 0 6px; font-size: 15px; }

/* "/" command suggestions, just above the chat input */
.cmd-suggest {
  position: absolute; left: 6px; right: 6px; bottom: calc(100% - 4px); z-index: 50;
  list-style: none; margin: 0; padding: 2px;
  max-height: 260px; overflow-y: auto;
  background: var(--stone-dark); border: 2px solid var(--edge-dark);
  box-shadow: inset 0 0 0 1px var(--stone-light), 0 -2px 0 #000;
  text-shadow: var(--shadow);
}
.chat .cmd-suggest { bottom: 42px; }
.cmd-suggest button {
  display: flex; flex-wrap: wrap; gap: 0 8px; align-items: baseline; width: 100%; text-align: left;
  background: none; border: 0; padding: 6px 8px; cursor: pointer; font: inherit; font-size: 14px;
  touch-action: manipulation;
}
.cmd-suggest button:hover, .cmd-suggest button:focus-visible { background: var(--stone-mid); outline: none; }
.cmd-suggest .cmd { color: var(--yellow); }
.cmd-suggest .desc { color: var(--beige); font-size: 12px; }
.cmd-suggest .empty { color: var(--muted); font-size: 13px; padding: 6px 8px; }

/* /roll and /work lines */
.chat-line .emote { color: #3a2a00; }
.chat-line .emote .actor { color: var(--ink); }
.chat-line .emote.roll .text { color: #5a0070; }
.chat-line .emote.work .text { color: #0b5a12; }
.chat-line.local .local-info { color: #5a2d00; font-style: italic; }

/* Game panels: a small dark stone tablet in the chat, so gold and red read clearly */
.chat-line.game, .chat-line.local { display: block; }
.chat-line.game .time, .chat-line.local .time { display: block; }
.game-slot { margin: 2px 0 4px; }
.game-panel {
  background: var(--stone-dark);
  border: 1px solid #000;
  box-shadow: inset 0 0 0 1px var(--stone-light);
  color: var(--beige); text-shadow: var(--shadow);
  padding: 6px 8px; font-size: 14px; max-width: 520px;
  overflow-wrap: anywhere;
}
.game-panel.live { box-shadow: inset 0 0 0 1px var(--gold); }
.game-panel p { margin: 4px 0 0; }
.gp-head { color: var(--orange); }
.gp-head strong { color: var(--yellow); font-weight: 500; }
.gp-icon { font-size: 15px; }
.gp-result { font-size: 15px; }
.gp-result.win { color: var(--gold); }
.gp-result.win.big { color: var(--yellow); font-size: 17px; letter-spacing: .5px; animation: shine 1.2s ease-in-out 3; }
@keyframes shine { 50% { text-shadow: 0 0 6px #ffd21f, 1px 1px 0 #000; } }
.gp-result.lose { color: #c86a5e; }
.gp-note { color: var(--muted); font-size: 13px; }
.game-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.game-btn { min-height: 32px; min-width: 64px; }
.hand { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.hand-label { min-width: 52px; color: var(--muted); font-size: 13px; }
.hand .total { color: var(--yellow); margin-left: 4px; }
.card {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 38px; padding: 0 3px;
  background: #f4ecd8; color: #111; text-shadow: none;
  border: 1px solid #000; border-radius: 3px; box-shadow: 1px 1px 0 #000;
  font-size: 15px;
}
.card.red { color: #b00000; }
.card.down { background: #6b2f2f; color: #f4ecd8; font-size: 22px; }
.rolls { list-style: none; margin: 4px 0 0; padding: 0; }
.rolls li { padding: 1px 0; }
.rolls strong { color: var(--white); font-weight: 500; }
.rolls li.one strong { color: var(--red); }
.wheel { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--white); }
.pocket {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--gold);
  background: #1c1813; color: #fff; font-size: 15px;
}
.pocket.red { background: #a01010; }
.pocket.black { background: #111; }
.pocket.green { background: #0a7a1e; }
.wheel.spinning .pocket { animation: spin .5s linear infinite; }
.wheel.spinning .card.down { animation: wobble .4s ease-in-out infinite alternate; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes wobble { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }
.countdown.urgent { color: var(--red); }

/* /help */
.game-panel.help dl { margin: 4px 0 0; }
.game-panel.help dt { color: var(--yellow); margin-top: 6px; }
.game-panel.help dd { margin: 1px 0 0 10px; font-size: 13px; }

/* SteveSlop card picker */
.card-grid { display: flex; flex-wrap: wrap; gap: 4px; }
.card-btn { min-width: 38px; min-height: 36px; font-size: 15px; }
.card-btn[aria-pressed="true"] { color: var(--yellow); background: #5a2b1e; border-color: var(--gold); }
.card-btn.suit-H, .card-btn.suit-D { color: #ff6b5a; }
.slop-pick { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--beige); }

/* Vote timers */
.timer-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin: -2px 0 8px; font-size: 14px; color: var(--yellow); }
.timer-row .countdown { font-size: 16px; }
.timer-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.timer-options .btn { min-height: 40px; }

/* ======================================================================= */
/* Phones & small tablets                                                  */
/* ======================================================================= */

@media (max-width: 899px) {
  .frame { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 0; }

  /* Compact header */
  .header { padding: 8px 10px; gap: 6px; margin-bottom: 10px; }
  h1 { font-size: 18px; }
  .subtitle { display: none; }
  .whoami { width: 100%; gap: 6px; flex-wrap: wrap; }
  #distribute-btn { order: 1; flex: 1 1 100%; min-height: 40px; }
  .whoami .me-button { min-width: 0; flex: 1; justify-content: flex-start; }
  .me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .gp-pill { flex: none; min-height: 40px; }
  #logout-btn { flex: none; min-height: 40px; }

  /* Single column; the sidebar becomes the Clan tab */
  .layout { display: block; }
  .sidebar { position: static; max-height: none; overflow: visible; display: none; }
  body[data-tab="clan"] .sidebar { display: block; }
  body[data-tab="clan"] .main, body[data-tab="chat"] .main { display: none; }

  /* Bottom tab bar */
  .mobile-only { display: flex; }
  .desktop-only { display: none; }
  .clan-list .member-side .btn { min-height: 36px; padding: 2px 10px; }
  .clan-list .role { font-size: 13px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    margin: 0; gap: 0;
    background: var(--stone-dark);
    border-top: 2px solid var(--edge-dark);
    box-shadow: 0 -1px 0 var(--edge-light), 0 -3px 0 #000;
    padding-bottom: var(--safe-b);
  }
  .tab {
    flex: 1 1 0; min-width: 0;
    flex-direction: column; gap: 1px;
    min-height: var(--tabbar-h); padding: 4px 0;
    font-size: 12px;
    background: transparent; border: 0; box-shadow: none;
  }
  .tab + .tab { border-left: 1px solid #000; }
  .tab-icon { font-size: 18px; line-height: 1; }
  .tab[aria-selected="true"] { box-shadow: none; }
  body.typing .tabs { display: none; } /* keyboard open: give the screen back */

  body.has-dock, body.has-dock.dock-collapsed { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); }

  /* Chat becomes a full-height tab instead of a dock */
  .dock { display: none; }
  body[data-tab="chat"] .dock {
    display: block;
    position: static; max-width: none;
    margin: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    padding: 4px;
  }
  .dock-bar { display: none; }
  .dock.collapsed .dock-body { display: block; }
  body[data-tab="chat"] .dock-body {
    /* header (~90px) + tab bar + breathing room */
    height: calc(100vh - 170px - var(--tabbar-h) - var(--safe-b));
    height: calc(100dvh - 170px - var(--tabbar-h) - var(--safe-b));
    min-height: 260px;
  }
  body.typing[data-tab="chat"] .dock-body { height: calc(100dvh - 120px); }
  .chat-log { font-size: 15px; }
  .chat-line .del { visibility: visible; }
  .chat-form { padding: 6px 6px 6px 8px; }
  .chat-prompt { display: none; }
  .chat-send { min-height: 40px; padding: 0 12px; }
  .cmd-btn { min-height: 40px; min-width: 40px; }
  .chat .cmd-suggest { bottom: 54px; max-height: 50vh; }
  .cmd-suggest button { padding: 10px 8px; font-size: 15px; }
  .game-btn { min-height: 44px; min-width: 80px; font-size: 15px; }
  .game-panel { font-size: 15px; }

  /* Bigger touch targets */
  .btn { min-height: 36px; }
  .btn-small { min-height: 40px; font-size: 14px; padding: 2px 12px; }
  .inline-form .btn, #topic-submit { min-height: 44px; }
  .column { min-height: 96px; }
  .plate { min-height: 30px; font-size: 15px; }
  .stake-btn { width: 44px; min-height: 44px; font-size: 22px; }
  .stake-controls .amount { font-size: 18px; }
  .topic-head { flex-direction: column; }
  .topic-actions { align-self: flex-end; margin-top: -4px; }
  .topic-image { max-height: 200px; }
  .clan-list li { padding: 8px 0; font-size: 16px; }
  .stake-list button { padding: 10px 2px; font-size: 15px; }
}

@media (max-width: 420px) {
  .frame { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .panel { padding: 10px; }
  .columns { gap: 6px; }
  .column { padding: 5px; }
  .column-head { flex-wrap: wrap; }
  .row { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- Shared bits for gold rules ------------------------------------------- */

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.short-label { display: none; }
.lock { font-size: 12px; margin-left: 2px; cursor: help; }
.new-tag {
  font-size: 11px; padding: 0 4px; color: #9fe39f; border: 1px solid #000; background: #1e3a1e;
  cursor: help; white-space: nowrap;
}
.pouch-lock { margin: 6px 0 0; padding: 6px; font-size: 13px; color: var(--yellow); background: var(--stone-dark); border: 1px solid #000; }
.pouch-lock .why { display: block; margin-top: 2px; color: var(--beige); font-size: 12px; }
.chat-line .emote.reward .text { color: #6b4a00; }
.badge.ok { color: var(--green); }

/* Vote timer dialog */
.timer-preview { margin: 0; color: var(--yellow); }
.timer-warning { margin: 0; padding: 6px; color: var(--beige); font-size: 14px; background: var(--stone-dark); border: 1px solid #000; }
select {
  font: inherit; font-size: 15px; color: var(--white); text-shadow: var(--shadow);
  background: var(--stone-dark); border: 1px solid var(--edge-dark);
  box-shadow: inset 1px 1px 0 #000, inset -1px -1px 0 var(--stone-light);
  padding: 5px 6px; border-radius: 0;
}

/* Admin settings */
.admin-settings { border-color: #3a0e0a; }

/* --- Resizable chat dock (desktop) ---------------------------------------- */

.dock-resize { position: absolute; z-index: 2; touch-action: none; }
.dock-resize.edge { left: 18px; right: 18px; top: -4px; height: 8px; cursor: ns-resize; }
.dock-resize.corner { top: -4px; width: 18px; height: 18px; }
.dock-resize.left { left: -2px; cursor: nwse-resize; }
.dock-resize.right { right: -2px; cursor: nesw-resize; }
/* A little grip, like a window corner */
.dock-resize.corner::after {
  content: ''; position: absolute; top: 6px; width: 10px; height: 10px;
  border-top: 2px solid var(--edge-light);
}
.dock-resize.left::after { left: 6px; border-left: 2px solid var(--edge-light); }
.dock-resize.right::after { right: 6px; border-right: 2px solid var(--edge-light); }
.dock-resize:hover::after, .dock-resize.edge:hover { border-color: var(--yellow); }
.dock-resize.edge:hover { border-top: 2px solid var(--yellow); }
.dock.collapsed .dock-resize { display: none; }
body.resizing, body.resizing * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

/* --- Job Board ------------------------------------------------------------ */

.job-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.job-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 1; justify-content: flex-end; }
.job-list { display: grid; gap: 10px; }
.job-card { display: flex; gap: 10px; cursor: pointer; margin-bottom: 0; }
.job-card:hover, .job-card:focus-visible { outline: 1px solid var(--gold); }
.job-card.status-completed, .job-card.status-cancelled { opacity: .75; }
.job-thumb { width: 120px; height: 100px; object-fit: cover; flex: none; border: 2px solid #000; box-shadow: 0 0 0 1px var(--edge-light); }
.job-main { flex: 1; min-width: 0; }
.job-head { display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.job-type { color: var(--beige); }
.job-type.type-item { color: #e8c27a; }
.job-type.type-service { color: var(--opt3); }
.job-type.type-group { color: #ff8a6b; }
.job-status { padding: 0 6px; border: 1px solid #000; background: var(--stone-dark); }
.st-open { color: var(--green); }
.st-full { color: var(--yellow); }
.st-in_progress { color: var(--opt3); }
.st-completed { color: var(--gold); }
.st-cancelled { color: #c86a5e; }
.job-title { margin: 4px 0 2px; color: var(--yellow); font-size: 18px; font-weight: 500; overflow-wrap: anywhere; }
.job-by { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.job-desc {
  margin: 6px 0 0; color: var(--white); font-size: 14px; overflow-wrap: anywhere; white-space: pre-wrap;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.job-facts { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 14px; color: var(--beige); }
.job-facts > span { overflow-wrap: anywhere; }
.job-facts .reward { color: var(--yellow); display: inline-flex; align-items: center; gap: 3px; }
.job-facts .slots { color: var(--white); }
.job-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.job-actions .signup { color: var(--yellow); }
.job-detail h3 { color: var(--orange); font-size: 16px; font-weight: 500; margin: 12px 0 4px; }
.job-full-desc { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--white); margin: 8px 0; }
.job-images { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.job-images img { max-width: 100%; height: 140px; object-fit: cover; border: 2px solid #000; box-shadow: 0 0 0 1px var(--edge-light); }
.job-signups, .pay-list { list-style: none; margin: 0; padding: 0; }
.job-signups li, .pay-list li { display: flex; align-items: center; gap: 6px; padding: 4px 0; flex-wrap: wrap; color: var(--white); }
.job-signups .gp { color: var(--yellow); }
.pay-list .pay-amount { width: 110px; flex: none; margin-left: auto; }
.pay-summary { color: var(--beige); margin: 8px 0 0; }
.type-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.type-pick .btn[aria-pressed="true"] { color: var(--yellow); background: #5a2b1e; border-color: var(--gold); }
.when-row { align-items: center; flex-wrap: wrap; }
.when-row input[type="datetime-local"] { flex: 1 1 200px; }
.field.qty { flex: 0 0 110px; }
.job-pictures { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.job-pic { position: relative; }
.job-pic img { width: 96px; height: 72px; object-fit: cover; border: 1px solid #000; display: block; }
.job-pic .plate-remove { position: absolute; top: 0; right: 0; background: rgba(0,0,0,.7); color: #fff; padding: 2px 5px; }

@media (max-width: 899px) {
  .dock-resize { display: none; }
  .long-label { display: none; }
  .short-label { display: inline; }
  .tabs .tab { font-size: 11px; }
  .job-toolbar { flex-direction: column; align-items: stretch; }
  .job-toolbar #job-new { min-height: 44px; }
  .job-filters { justify-content: flex-start; }
  .job-filters label:not(.check-row) { flex: 1 1 45%; }
  .job-filters select { width: 100%; min-height: 40px; }
  .job-filters .check-row { min-height: 40px; }
  .job-card { flex-direction: column; }
  .job-thumb { width: 100%; height: 140px; }
  .job-actions .btn { min-height: 44px; min-width: 96px; }
  .type-pick .btn { flex: 1 1 100%; }
  .pay-list .pay-amount { width: 90px; }
  .job-images img { height: 110px; }
}
