:root {
  --bg: #C7B39F;
  --panel: #BEAC99;
  --panel-dark: #B7A593;
  --btn: #B2A190;
  --btn-hover: #A89685;
  --outline: #645A50;
  --ink: #14120F;
  --decline: #CE6C6C;
  --accept: #97C277;
  --light-sq: #EDD6B0;
  --dark-sq: #B88762;
  --hand: 'Gochi Hand', 'Comic Sans MS', 'Segoe Print', cursive;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { font-family: var(--hand); overflow-x: hidden; }
img { -webkit-user-drag: none; user-select: none; }
.hidden { display: none !important; }
.hand { font-family: var(--hand); }
.small { font-size: 18px; opacity: .8; }
.center { text-align: center; }

.screen { min-height: 100vh; min-height: 100dvh; position: relative; padding: 24px 16px 40px; }

/* ---------- buttons (your drawn button style) ---------- */
.btn {
  background: var(--btn); border: 1px solid var(--outline); padding: 10px 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; transition: background .12s, transform .08s;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(.97); }
.btn img { display: block; pointer-events: none; }
.btn.big { width: 210px; height: 72px; }
.btn.big img { max-height: 54px; max-width: 180px; }
.text-btn .hand { font-size: 24px; color: var(--ink); }
.back {
  position: absolute; top: 14px; left: 14px; z-index: 5; font: 30px var(--hand); width: 52px; height: 52px;
  background: var(--btn); border: 1px solid var(--outline); cursor: pointer; color: var(--ink);
}
.panel { background: var(--panel); }
.panel.dark { background: var(--panel-dark); }
.narrow { max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; }
.narrow.wide { max-width: 1000px; }
.title { max-width: min(560px, 82vw); height: auto; }

/* ---------- main menu ---------- */
#menu { padding-top: 0; }
.logo { position: absolute; top: 0; left: 0; width: min(345px, 52vw); height: auto; }
.userbadge {
  position: absolute; top: 24px; right: 24px; display: flex; align-items: center; gap: 10px;
  background: var(--btn); border: 2px solid var(--outline); padding: 8px 14px 8px 8px; color: #fff; font-size: 26px;
}
.userbadge img { width: 44px; height: auto; display: block; }
.menu-options {
  display: flex; justify-content: space-around; align-items: flex-end; gap: 24px;
  max-width: 1300px; margin: 0 auto; padding-top: min(30vh, 340px);
}
.option { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.option .icon { height: 150px; width: auto; }

/* ---------- bots ---------- */
#bots .narrow { gap: 12px; padding-top: 10px; }
.bot-grid { width: 100%; padding: 14px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; min-height: 140px; }
.bot-card { cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; padding: 0; font-family: var(--hand); }
.bot-card .portrait {
  width: 100%; aspect-ratio: 1; background: var(--btn); border: 2px solid var(--outline); display: flex; align-items: flex-end; justify-content: center; overflow: hidden;
}
.bot-card .portrait img { width: 92%; height: auto; display: block; }
.bot-card.selected .portrait { border: 5px solid #fff; }
.bot-card .bname { font-size: 22px; color: #463E37; line-height: 1.1; text-align: center; }
.bot-card.selected .bname { color: #fff; }
.btn.select { width: min(563px, 90%); height: 120px; margin-top: 8px; }
.btn.select img { max-height: 100px; max-width: 90%; }

/* ---------- settings ---------- */
.settings-head { display: flex; align-items: flex-end; justify-content: center; gap: 30px; width: 100%; margin-bottom: 30px; }
.settings-head .title { width: min(446px, 46vw); }
.opponent-card { display: flex; flex-direction: column; align-items: center; }
.opponent-card img { width: min(300px, 34vw); height: auto; display: block; }
.opponent-card .hand { font-size: 26px; }
.settings-panel { width: 100%; display: flex; align-items: stretch; justify-content: space-between; padding: 14px 16px; min-height: 300px; }
.set-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 6px; }
.set-col .label { max-width: 220px; height: auto; }
.wavy.v { height: auto; max-height: 300px; align-self: stretch; width: 32px; object-fit: fill; }
.wavy.h { display: none; }
.colour-boxes { display: flex; gap: 30px; }
.colour { width: 72px; height: 72px; border: 2px solid var(--outline); cursor: pointer; }
.colour.white { background: #fff; }
.colour.black { background: #181818; }
.colour.selected { outline: 4px solid #fff; outline-offset: 4px; }
.colour.black.selected { outline-color: #fff; }
.time-options { display: grid; grid-template-columns: auto auto; gap: 10px 14px; align-items: center; }
.btn.time { width: 112px; height: 62px; padding: 6px; }
.btn.time img { max-height: 46px; max-width: 96px; }
.btn.time[data-time="0"] { grid-row: 1 / span 2; grid-column: 2; }
.btn.time.selected, .btn.start:hover { background: #fff; }
.btn.start { width: 132px; height: 158px; }
.btn.start img { max-width: 110px; max-height: 80px; margin-bottom: 40px; }

/* ---------- friends ---------- */
.friends-panel { width: min(400px, 100%); min-height: 388px; padding: 11px; margin-top: 50px; }
.search { display: flex; gap: 25px; padding-left: 46px; }
.search input {
  flex: 1; min-width: 0; height: 38px; border: 0; background: #B0A08F; font-size: 22px; padding: 0 10px; color: var(--ink); outline: none;
}
.search input::placeholder { color: #6f6256; }
.icon-btn { width: 42px; height: 38px; padding: 4px; }
.icon-btn img { max-height: 28px; }
.results { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.results .hint { font-size: 19px; opacity: .75; padding: 6px; }
.result {
  display: flex; align-items: center; gap: 10px; background: var(--btn); border: 1px solid var(--outline); padding: 6px 10px;
  cursor: pointer; font: 22px var(--hand); color: var(--ink); text-align: left;
}
.result:hover { background: #fff; }
.result img { width: 34px; }
.result .status { margin-left: auto; font-size: 17px; opacity: .75; }
.result.busy { opacity: .55; cursor: default; }

/* ---------- queue ---------- */
.queue-panel { width: min(672px, 100%); margin-top: 12vh; padding: 28px 26px 22px; display: flex; flex-direction: column; gap: 16px; }
.queueing { width: min(605px, 100%); height: auto; }
.q-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.q-row img { height: 52px; width: auto; max-width: 70%; }
.q-val { font-size: 34px; border-bottom: 1.5px solid var(--ink); min-width: 110px; padding: 0 8px; }
.queue-panel .text-btn { align-self: center; margin-top: 10px; }

/* ---------- game ---------- */
#game { padding: 12px 10px 30px; }
.game-wrap { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.player-row { display: flex; align-items: center; gap: 12px; padding-left: 44px; min-height: 52px; }
.player-row .avatar { width: 46px; height: 46px; object-fit: cover; background: #A9A9A9; }
.player-row .pname { font-size: 28px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock {
  margin-left: auto; min-width: 104px; padding: 4px 12px; text-align: center; font: 600 26px/1.3 'Segoe UI', system-ui, sans-serif;
  background: var(--btn); color: #fff; border: 2px solid var(--outline); font-variant-numeric: tabular-nums;
}
.clock.running { background: #fff; color: #28241F; }
.clock.low.running { background: #F3C3C3; }
.board-area { display: grid; grid-template-columns: 38px 1fr; grid-template-rows: auto 34px; }
.ranks { display: grid; grid-template-rows: repeat(8, 1fr); align-items: center; justify-items: center; font-size: 30px; }
.files { grid-column: 2; display: grid; grid-template-columns: repeat(8, 1fr); justify-items: center; font-size: 28px; }
.board { position: relative; width: 100%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); touch-action: none; user-select: none; }
.sq { position: relative; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.last.light { background: #D8D27F; }
.sq.last.dark { background: #B4A548; }
.sq.sel { background: #8FC47F !important; }
.sq.check { background: radial-gradient(circle, #ff3b3b 0%, #e23030 30%, rgba(200,0,0,0) 72%) !important; }
.sq .dot { position: absolute; inset: 37%; border-radius: 50%; background: rgba(20,20,20,.28); pointer-events: none; }
.sq .ring { position: absolute; inset: 4%; border-radius: 50%; border: 5px solid rgba(20,20,20,.28); pointer-events: none; }
.cg-wrap piece {
  position: absolute; inset: 0; background-size: cover; background-repeat: no-repeat; pointer-events: none; z-index: 2;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.cg-wrap piece.drag { position: fixed; inset: auto; z-index: 50; transform: translate(-50%, -50%); }
.cg-wrap piece.lifted { opacity: .35; }
/* fallback when the piece images can't load: Unicode chess symbols */
.cg-wrap.glyphs piece { font-size: min(9.5vw, 54px); font-family: 'Segoe UI Symbol', 'DejaVu Sans', 'Noto Sans Symbols 2', serif; }
.cg-wrap.glyphs piece.white { color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 0 1px #000; }
.cg-wrap.glyphs piece.black { color: #111; }
.banner { text-align: center; font-size: 22px; background: var(--panel-dark); padding: 6px 10px; }
.promo { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 60; }
.promo .choices { display: flex; gap: 8px; background: var(--panel); padding: 10px; border: 2px solid var(--outline); }
.promo .choice { width: 74px; height: 74px; position: relative; background: var(--light-sq); border: 1px solid var(--outline); cursor: pointer; }

/* ---------- popups ---------- */
.overlay { position: fixed; inset: 0; background: rgba(60,50,40,.35); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
#end-overlay { background: rgba(199,179,159,.93); }
.popup { background: var(--bg); display: flex; flex-direction: column; align-items: center; }
.popup.end { background: none; gap: 10px; }
#end-title { max-height: 120px; max-width: 80vw; }
#end-reason { max-height: 76px; max-width: 86vw; }
.end-extra { font-size: 26px; min-height: 10px; }
.btn.gomenu { width: 236px; height: 94px; margin-top: 50px; }
.btn.gomenu img { max-height: 68px; }
.popup.duel { background: var(--panel-dark); width: min(672px, 100%); min-height: 300px; padding: 22px 30px 22px; align-items: stretch; gap: 10px; }
.duel-title { max-width: 470px; width: 80%; height: auto; }
.duel-from { display: flex; align-items: flex-end; gap: 14px; }
.duel-from img { height: 46px; }
.duel-from .hand { font-size: 34px; border-bottom: 1.5px solid var(--ink); padding: 0 10px; min-width: 170px; }
.duel-info { font-size: 24px; margin-top: 12px; }
.big-hand { font-size: 36px; }
.duel-buttons { display: flex; justify-content: space-between; margin-top: auto; padding-top: 24px; }
.duel-buttons.center { justify-content: center; }
.btn.decline { background: var(--decline); width: 186px; height: 65px; }
.btn.accept { background: var(--accept); width: 186px; height: 65px; }
.btn.decline:hover { background: #D97F7F; } .btn.accept:hover { background: #A6CE88; }
.btn.decline img, .btn.accept img { max-height: 50px; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; font-size: 22px; z-index: 90; max-width: 90vw; text-align: center; }
.conn { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); background: var(--panel-dark); padding: 4px 14px; font-size: 20px; z-index: 95; border: 1px solid var(--outline); }

/* ---------- phones: everything stacks ---------- */
@media (max-width: 760px) {
  .screen { padding: 16px 12px 32px; }
  .userbadge { top: 128px; right: 50%; transform: translateX(50%); font-size: 22px; white-space: nowrap; }
  .userbadge img { width: 38px; }
  .logo { width: min(330px, 62vw); }
  .menu-options { flex-direction: column; align-items: center; gap: 34px; padding-top: 220px; }
  .option .icon { height: 130px; }
  .btn.big { width: min(420px, 82vw); height: 96px; }
  .btn.big img { max-height: 70px; max-width: 90%; }
  .back { width: 46px; height: 46px; font-size: 26px; }
  #bots .narrow { padding-top: 46px; }
  .bot-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-head { gap: 10px; margin-top: 40px; margin-bottom: 18px; }
  .settings-panel { flex-direction: column; align-items: center; padding: 18px 10px; }
  .wavy.v { display: none; }
  .wavy.h { display: block; width: 80%; height: 34px; object-fit: fill; margin: 8px 0; }
  .time-options { grid-template-columns: auto auto auto; }
  .btn.time[data-time="0"] { grid-row: auto; grid-column: auto; }
  .btn.start { width: 150px; height: 140px; }
  .friends-panel { margin-top: 56px; }
  .queue-panel { margin-top: 60px; padding: 20px 16px; }
  .q-row img { height: 40px; }
  .player-row { padding-left: 0; }
  .player-row .pname { font-size: 24px; }
  .board-area { grid-template-columns: 24px 1fr; grid-template-rows: auto 28px; }
  .ranks { font-size: 22px; } .files { font-size: 22px; }
  .popup.duel { padding: 18px 16px; }
  .btn.decline, .btn.accept { width: 140px; }
}
