/* H8: main menu, match setup, in-game menu, options and confirmations. The main menu sits over a match between AIs
   that plays in the background. Sizes scale with the interface option (--ui-scale, set by ui/menus.js). */

:root { --ui-scale: 1; }
.panel, .toast, .paused, dialog, .menu-screen { zoom: var(--ui-scale); }

/* Only the menu while it is open: the match behind it is scenery. */
body.in-menu .panel, body.in-menu .toast, body.in-menu .paused { display: none !important; }
body.in-menu #game { cursor: default; pointer-events: none; }
body:not(.in-menu) .menu { display: none; }

.menu {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  background:
    linear-gradient(90deg, rgba(8, 10, 13, 0.92) 0%, rgba(8, 10, 13, 0.72) 32%, rgba(8, 10, 13, 0.18) 62%, rgba(8, 10, 13, 0) 100%),
    linear-gradient(0deg, rgba(8, 10, 13, 0.55), rgba(8, 10, 13, 0) 30%);
}
.menu-screen { animation: menu-in 360ms var(--ease-out) backwards; }
@keyframes menu-in { from { opacity: 0; transform: translateY(8px); } }

.menu-home { display: flex; flex-direction: column; gap: var(--space-6); margin-left: clamp(24px, 8vw, 140px); width: 340px; }
.menu-title h1 { margin: 0; font: 700 44px/1.08 var(--font-title); letter-spacing: 0.04em; color: var(--primary); text-shadow: 0 2px 18px rgba(0, 0, 0, 0.7); }
.menu-title p { margin: var(--space-2) 0 0; color: var(--text-secondary); font-size: var(--fs-md); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8); }
.menu-nav { display: flex; flex-direction: column; gap: var(--space-2); }
.menu-btn {
  justify-content: space-between;
  min-height: 52px;
  padding: 0 var(--space-5);
  border-radius: 6px;
  border-color: var(--frame-edge);
  background: linear-gradient(180deg, var(--btn-top), var(--btn-bottom));
  box-shadow: inset 0 1px 0 var(--frame-light), 0 6px 18px -10px rgba(0, 0, 0, 0.8);
  font: 600 var(--fs-lg)/1.2 var(--font-title);
  letter-spacing: 0.03em;
  text-align: left;
}
.menu-btn small { font: 400 var(--fs-xs)/1.2 var(--font-ui); color: var(--text-muted); letter-spacing: 0; }
.menu-btn.primary { border-color: var(--primary-solid); color: var(--primary); }
@media (hover: hover) {
  .menu-btn:hover { background: linear-gradient(180deg, #34363c, #202227); border-color: var(--primary-solid); }
}
.menu-version { margin: 0; font-size: var(--fs-xs); color: var(--text-muted); }

.menu-card {
  margin: auto;
  width: min(940px, calc(100vw / var(--ui-scale) - 32px));
  max-height: calc(100vh / var(--ui-scale) - 32px);
  overflow: auto;
  padding: var(--space-6);
  background: linear-gradient(180deg, var(--frame-top), var(--frame-bottom));
  border: 1px solid var(--frame-edge);
  border-radius: var(--radius-frame);
  box-shadow: inset 0 0 0 1px var(--frame-inner), inset 0 1px 0 var(--frame-light), var(--shadow-panel);
}
.menu-card h2, .sheet h2 { margin: 0 0 var(--space-4); font: 700 26px/1.2 var(--font-title); letter-spacing: 0.03em; color: var(--primary); }
.menu-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }
.menu-actions .btn { min-height: 44px; width: auto; margin: 0; padding: 0 var(--space-5); }

.setup-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.setup fieldset { margin: 0; padding: var(--space-3) var(--space-4) var(--space-2); min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: rgba(0, 0, 0, 0.18); }
.setup legend { padding: 0 var(--space-1); font: 700 var(--fs-sm)/1.2 var(--font-title); letter-spacing: 0.05em; color: var(--primary); }
.setup .field, .options .field { grid-template-columns: 1fr; gap: 4px; margin-bottom: var(--space-3); }
.setup .field-note, .options .field-note { margin: -4px 0 var(--space-3); grid-column: auto; }
.setup .group-label { margin: var(--space-2) 0 0; }
.toggle span { padding-right: var(--space-3); }

.credits { width: min(620px, calc(100vw / var(--ui-scale) - 32px)); }
.credits p { margin: 0 0 var(--space-4); color: var(--text-secondary); }
.credits dl { margin: 0; display: grid; grid-template-columns: 110px 1fr; gap: var(--space-2) var(--space-4); font-size: var(--fs-sm); }
.credits dt { font-weight: 700; color: var(--text); }
.credits dd { margin: 0; color: var(--text-secondary); }

/* Top-right bar during a match: speed, tech tree and menu. */
.game-bar { top: var(--space-4); right: var(--space-4); display: flex; align-items: center; gap: var(--space-2); padding: 6px; }
.game-bar select { height: 40px; padding: 0 var(--space-2); background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font: 600 var(--fs-sm) var(--font-ui); }
.game-bar .btn-icon { border-color: var(--frame-edge); background: linear-gradient(180deg, var(--btn-top), var(--btn-bottom)); }
.stats { top: 76px; }
.glyph { display: block; width: 20px; height: 20px; background: center / contain no-repeat; }
.glyph-menu { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cg stroke='%23e2bd68' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 5.5h12M4 10h12M4 14.5h12'/%3E%3C/g%3E%3C/svg%3E"); }
.glyph-tree { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cg fill='none' stroke='%23e2bd68' stroke-width='1.6' stroke-linejoin='round'%3E%3Crect x='7' y='2.5' width='6' height='4' rx='1'/%3E%3Crect x='2' y='13.5' width='6' height='4' rx='1'/%3E%3Crect x='12' y='13.5' width='6' height='4' rx='1'/%3E%3Cpath d='M10 6.5v3.5M5 13.5V10h10v3.5'/%3E%3C/g%3E%3C/svg%3E"); }

/* Sheets: in-game menu, options and confirmations. */
.sheet { padding: var(--space-6); background: linear-gradient(180deg, #1b1c20, #0f1013); border-color: var(--frame-edge); border-radius: var(--radius-frame); box-shadow: inset 0 1px 0 var(--frame-light), var(--shadow-panel); }
.sheet[open] { animation: menu-in 260ms var(--ease-out); }
.sheet::backdrop { background: rgba(5, 7, 10, 0.62); backdrop-filter: blur(3px); }
.game-menu { width: min(400px, calc(100vw - 32px)); }
.game-menu .meta { margin: -6px 0 var(--space-4); }
.sheet-list { display: flex; flex-direction: column; gap: var(--space-2); }
.sheet-list .btn { width: 100%; min-height: 48px; margin: 0; }
.btn.danger { color: var(--danger); }
.btn.danger-solid { background: #8f2a22; border-color: transparent; color: #fff4f2; }
@media (hover: hover) { .btn.danger-solid:hover { background: #a8342b; } }

.options { width: min(620px, calc(100vw - 32px)); padding: 0; }
.options-head { padding: var(--space-6) var(--space-6) 0; }
.options-head h2 { margin-bottom: var(--space-3); }
.options .tabs { display: flex; gap: var(--space-2); border-bottom: 1px solid var(--border); }
.options .tab { min-height: 40px; padding: 0 var(--space-4); margin-bottom: -1px; border: 1px solid transparent; border-radius: 6px 6px 0 0; background: none; color: var(--text-secondary); font: 600 var(--fs-md)/1 var(--font-ui); cursor: pointer; }
.options .tab.active { border-color: var(--border); border-bottom-color: #18191d; background: #18191d; color: var(--primary); }
.options-body { padding: var(--space-4) var(--space-6); height: min(470px, calc(100vh - 220px)); overflow: auto; }
.options .toggle { border-bottom: 1px solid rgba(255, 255, 255, 0.04); font-size: var(--fs-md); }
.options .field select { height: 40px; }
.options .help { margin: 0 0 var(--space-3); }
.sheet-foot { display: flex; justify-content: flex-end; padding: var(--space-4) var(--space-6) var(--space-5); border-top: 1px solid var(--border); }
.sheet-foot .btn-primary { width: auto; margin: 0; padding: 0 var(--space-6); }

.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 2px var(--space-4); margin-bottom: var(--space-4); }
.key-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 40px; font-size: var(--fs-sm); color: var(--text-secondary); }
.key-row .btn { min-width: 64px; min-height: 34px; padding: 0 var(--space-2); font: 700 var(--fs-sm)/1 var(--font-ui); color: var(--primary); }
.key-row .btn.listening { border-color: var(--primary-solid); background: var(--primary-soft); }
.key-row.clash .btn { border-color: var(--danger); color: var(--danger); }

.confirm { width: min(420px, calc(100vw - 32px)); }
.confirm p { margin: 0 0 var(--space-5); color: var(--text-secondary); }
.confirm .actions { display: flex; justify-content: flex-end; gap: var(--space-2); }
.confirm .actions .btn { min-height: 44px; }

.result .actions .btn-primary { margin: 0; }

@media (max-width: 860px) {
  .setup-grid { grid-template-columns: 1fr; }
  .keys { grid-template-columns: 1fr; }
  .menu-home { margin: auto; }
}

@media (max-width: 1100px) {
  .resources { left: var(--space-4); transform: none; }
}

/* Saved games */
.loads { width: min(640px, calc(100vw - 32px)); }
.loads .field-note { margin: -8px 0 var(--space-3); }
.save-list { display: flex; flex-direction: column; gap: var(--space-2); max-height: min(420px, calc(100vh - 260px)); overflow: auto; }
.save-row { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: 6px; background: rgba(0, 0, 0, 0.2); }
.save-row .what { flex: 1; min-width: 0; }
.save-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.save-row small { color: var(--text-muted); font-size: var(--fs-xs); }
.save-row .btn { min-height: 40px; }
.save-row .btn-primary { width: auto; margin: 0; }
.save-empty { padding: var(--space-5); text-align: center; color: var(--text-muted); border: 1px dashed var(--border); border-radius: 6px; }
.loads-foot { display: flex; justify-content: space-between; gap: var(--space-2); margin-top: var(--space-4); }
.loads-foot .btn-primary { width: auto; margin: 0; padding: 0 var(--space-5); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.volumes { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-3); }
.volume { display: grid; grid-template-columns: 110px 1fr 52px; align-items: center; gap: var(--space-3); min-height: 40px; color: var(--text-secondary); }
.volume input { width: 100%; accent-color: var(--primary-solid); }
.volume output { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }

/* Tutorial */
.tutorial { top: 76px; left: var(--space-4); width: 340px; padding: var(--space-4); animation: menu-in 300ms var(--ease-out); }
.tutorial h2 { margin: var(--space-2) 0 var(--space-1); font: 700 var(--fs-xl)/1.2 var(--font-title); color: var(--primary); letter-spacing: 0.02em; }
.tutorial p { margin: 0 0 var(--space-3); color: var(--text-secondary); font-size: var(--fs-md); line-height: 1.5; }
.tutorial p strong { color: var(--text); }
.tutorial kbd { font: 600 12px var(--font-ui); padding: 1px 6px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-2); color: var(--primary); }
.tut-head { display: flex; align-items: center; gap: var(--space-3); font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.tut-progress { flex: 1; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.tut-progress span { display: block; height: 100%; background: var(--primary-solid); transition: width 300ms var(--ease-out); }
.tut-actions { display: flex; gap: var(--space-2); }
.tut-actions .btn { min-height: 36px; font-size: var(--fs-sm); }

/* Closing the desktop game: the window fades while the launcher shuts it. */
body.closing { opacity: 0; transition: opacity 300ms var(--ease-out); }
.toggle kbd { font: 600 11px var(--font-ui); padding: 1px 5px; margin-left: 6px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-2); color: var(--text-secondary); }

/* Accounts and profile */
.match-list { display: flex; flex-direction: column; gap: 4px; max-height: 170px; overflow: auto; margin-bottom: var(--space-3); }
.match-row { display: flex; align-items: center; gap: var(--space-2); padding: 4px var(--space-2); border: 1px solid var(--border); border-radius: 6px; font-size: var(--fs-sm); }
.match-row .what { flex: 1; min-width: 0; color: var(--text-secondary); }
.match-row .what b.won { color: #8fd18f; }
.match-row .what b.lost { color: var(--danger); }
.match-row .btn { min-height: 32px; padding: 0 var(--space-3); font-size: var(--fs-sm); }
.match-empty { color: var(--text-muted); font-size: var(--fs-sm); margin: 0 0 var(--space-3); }
.menu-home .account-chip { align-self: flex-start; }
.account-chip { display: flex; align-items: center; gap: var(--space-3); padding: 6px var(--space-3) 6px 6px; border-radius: 6px; border: 1px solid var(--frame-edge); background: rgba(10, 12, 16, 0.75); color: var(--text); cursor: pointer; text-align: left; font: inherit; }
.account-chip small { display: block; color: var(--text-muted); font-size: var(--fs-xs); }
.account-chip strong { font-family: var(--font-title); color: var(--primary); }
.chip-portrait, .profile-portrait, .portraits .icon { border-radius: 6px; border: 1px solid var(--frame-edge); background-color: var(--portrait-bg); box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.55); }
.chip-portrait { width: 40px; height: 40px; overflow: hidden; }
.account { width: min(460px, calc(100vw / var(--ui-scale) - 32px)); }
.account .field, .profile .field { grid-template-columns: 1fr; gap: 4px; margin-bottom: var(--space-3); }
.account .field small { color: var(--text-muted); }
.account-tabs { display: flex; gap: var(--space-2); margin-bottom: var(--space-4); border-bottom: 1px solid var(--border); }
.account-tabs .tab { min-height: 40px; padding: 0 var(--space-4); margin-bottom: -1px; border: 1px solid transparent; border-radius: 6px 6px 0 0; background: none; color: var(--text-secondary); font: 600 var(--fs-md)/1 var(--font-ui); cursor: pointer; }
.account-tabs .tab.active { border-color: var(--border); border-bottom-color: #18191d; background: #18191d; color: var(--primary); }
.profile { width: min(780px, calc(100vw / var(--ui-scale) - 32px)); }
.profile-grid { display: grid; grid-template-columns: 220px 1fr; gap: var(--space-5); }
.profile-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: var(--space-4); border: 1px solid var(--border); border-radius: 6px; background: rgba(0, 0, 0, 0.2); text-align: center; }
.profile-card strong { font: 700 var(--fs-xl)/1.2 var(--font-title); color: var(--primary); }
.profile-card small { color: var(--text-muted); }
.profile-portrait { width: 128px; height: 128px; overflow: hidden; margin-bottom: var(--space-2); }
.profile-stats { display: grid; grid-template-columns: 1fr auto; gap: 4px var(--space-3); margin: var(--space-3) 0 0; width: 100%; font-size: var(--fs-sm); text-align: left; }
.profile-stats dt { color: var(--text-muted); }
.profile-stats dd { margin: 0; color: var(--text); font-weight: 700; text-align: right; }
.portraits { display: grid; grid-template-columns: repeat(auto-fill, 56px); gap: 6px; max-height: 200px; overflow: auto; margin-bottom: var(--space-3); }
.portraits button { padding: 0; border: 2px solid transparent; border-radius: 8px; background: none; cursor: pointer; }
.portraits button[aria-checked="true"] { border-color: var(--primary-solid); }
.password-box { margin-top: var(--space-2); padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: 6px; }
.password-box summary { cursor: pointer; color: var(--text-secondary); min-height: 32px; line-height: 32px; }
.menu-actions .spacer { flex: 1; }
@media (max-width: 760px) { .profile-grid { grid-template-columns: 1fr; } }

/* Online: room list, rooms, chat and the server's pauses */
.online, .room { width: min(940px, calc(100vw / var(--ui-scale) - 32px)); }
.online-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.online-head h2 { margin: 0; }
#room-code { font-family: var(--font-ui); letter-spacing: 0.15em; color: var(--text); }
.online-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.online-actions .btn-primary { width: auto; margin: 0; padding: 0 var(--space-5); }
.toggle.compact { min-height: 32px; gap: var(--space-2); }
.join-code { display: flex; gap: var(--space-2); margin-left: auto; }
.join-code input { width: 120px; height: 40px; padding: 0 var(--space-3); background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font: 600 var(--fs-md) var(--font-ui); letter-spacing: 0.12em; text-transform: uppercase; }
.room-list { display: flex; flex-direction: column; gap: var(--space-2); min-height: 120px; max-height: min(380px, calc(100vh - 340px)); overflow: auto; }
.room-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: 6px; background: rgba(0, 0, 0, 0.2); }
.room-row .what { flex: 1; min-width: 0; }
.room-row strong { display: block; color: var(--text); }
.room-row small { color: var(--text-muted); }
.room-empty { padding: var(--space-5); text-align: center; color: var(--text-muted); border: 1px dashed var(--border); border-radius: 6px; }
.room-grid { display: grid; grid-template-columns: 1fr 300px; gap: var(--space-5); }
.slots { display: flex; flex-direction: column; gap: 6px; }
.slot { display: grid; grid-template-columns: 10px 44px 1fr 140px 96px 110px 36px; align-items: center; gap: var(--space-2); min-height: 52px; padding: 4px var(--space-2); border: 1px solid var(--border); border-radius: 6px; background: rgba(0, 0, 0, 0.2); }
.slot.empty { border-style: dashed; }
.slot .swatch { width: 10px; height: 36px; border-radius: 3px; }
.slot .chip-portrait { width: 44px; height: 44px; }
.slot .who { min-width: 0; }
.slot .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot .who small { color: var(--text-muted); }
.slot select { height: 36px; width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; font-size: var(--fs-sm); }
.slot .state { font-size: var(--fs-sm); color: var(--text-muted); }
.slot .state.ready { color: #8fd18f; font-weight: 700; }
.slot .btn-icon { width: 36px; min-width: 36px; min-height: 36px; }
.room-settings { margin: 0; padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-sm); background: rgba(0, 0, 0, 0.18); }
.room-settings legend { padding: 0 var(--space-1); font: 700 var(--fs-sm)/1.2 var(--font-title); letter-spacing: 0.05em; color: var(--primary); }
.room-settings .field { grid-template-columns: 1fr; gap: 4px; margin-bottom: var(--space-2); }
.room-settings:disabled { opacity: 0.85; }
.chat-log { height: 130px; overflow: auto; padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: 6px; background: rgba(0, 0, 0, 0.25); font-size: var(--fs-sm); color: var(--text-secondary); }
.chat-log p, .game-chat p { margin: 0 0 2px; }
.chat-log b, .game-chat b { color: var(--primary); font-weight: 700; }
.chat-form { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.chat-form input, .chat-bar input { flex: 1; height: 40px; padding: 0 var(--space-3); background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; }
.net-pause { top: 30%; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: var(--space-4) var(--space-6); text-align: center; z-index: 4; }
.net-pause strong { font: 700 var(--fs-xl)/1.2 var(--font-title); color: var(--primary); }
.net-pause span { color: var(--text-secondary); }
.game-chat { position: fixed; left: var(--space-4); bottom: 250px; width: min(420px, 40vw); pointer-events: none; font-size: var(--fs-sm); color: var(--text); text-shadow: 0 1px 3px #000, 0 0 6px #000; zoom: var(--ui-scale); }
.game-chat p { animation: chat-fade 12s forwards; }
@keyframes chat-fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
.chat-bar { left: var(--space-4); bottom: 200px; width: min(460px, 44vw); padding: 6px; display: flex; }
body.in-menu .game-chat { display: none; }
body.online #speed { display: none; }
@media (max-width: 900px) { .room-grid { grid-template-columns: 1fr; } .slot { grid-template-columns: 10px 44px 1fr 110px; } .slot > :nth-child(n+5) { grid-column: span 1; } }
