/* =========================================================
   GoChess Board — UI
   Coherent desktop application shell: header, board workspace,
   unified inspector (tabs), position dialog. Mobile-first.
   ========================================================= */

:root {
  --c-bg: #ebebed;
  --c-surface: #ffffff;
  --c-surface-2: #f5f5f7;
  --c-elevated: #ffffff;
  --c-border: #e4e4e8;
  --c-border-strong: #cfcfd6;
  --c-text: #1d1d1f;
  --c-text-soft: #54545a;
  --c-text-muted: #86868d;

  --c-primary: #0d8a7a;
  --c-primary-hover: #0a7367;
  --c-primary-soft: #e3f3f0;

  --c-success: #1f9d57;
  --c-success-hover: #188449;

  --c-danger: #d63b3b;
  --c-danger-hover: #c02e2e;

  --c-neutral: #e8e8ec;
  --c-neutral-hover: #dadadf;
  --c-neutral-text: #4b4b52;

  --c-accent: #c98a16;
  --c-accent-soft: #fdf3e3;

  --c-warning: #c98a16;
  --c-focus-ring: #0d8a7a;

  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 13px;
  --r-xl: 18px;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s7: 32px;

  --btn-h: 40px;
  --btn-h-sm: 34px;
  --input-h: 40px;

  --shadow-card: 0 1px 2px rgba(15,23,42,.03), 0 1px 3px rgba(15,23,42,.06);
  --shadow-elevated: 0 2px 8px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.04);
  --shadow-pop: 0 12px 40px rgba(15,23,42,.16), 0 2px 8px rgba(15,23,42,.08);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Courier New', ui-monospace, monospace;

  --t-fast: .15s ease;
  --t-mid: .18s ease;
}

/* ----- Base ----- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}
h1, h2, h3, p { margin: 0; }
.icon { width: 18px; height: 18px; display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* ----- App shell ----- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1320px;
  margin: 0 auto;
  background: var(--c-surface);
  box-shadow: 0 0 0 1px var(--c-border);
}

/* ----- Application header ----- */
.app-header {
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: 52px;
  padding: 0 var(--s4);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}
.app-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--c-text);
  display: flex;
  align-items: center;
  gap: var(--s2);
  white-space: nowrap;
}
.app-title .icon { color: var(--c-primary); }
.app-header-status {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-width: 0;
  overflow: hidden;
}
.header-status {
  font-size: 13px;
  color: var(--c-text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-opening {
  font-size: 12px;
  color: var(--c-accent);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ----- Language switcher ----- */
.lang-switcher {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  background: var(--c-neutral);
  border-radius: var(--r-sm);
  padding: 2px;
}
.lang-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--c-text-soft);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.lang-btn:hover { color: var(--c-text); }
.lang-btn.is-active {
  background: var(--c-surface);
  color: var(--c-primary);
  box-shadow: 0 1px 2px rgba(15,23,42,.08);
}
.lang-btn:focus-visible { outline: 2px solid var(--c-focus-ring); outline-offset: 1px; }

/* ----- Main layout ----- */
.app-main {
  flex: 1;
  display: flex;
  gap: var(--s4);
  padding: var(--s4);
  min-height: 0;
  overflow: hidden;
}

/* ----- Board workspace ----- */
.board-workspace {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  flex-shrink: 0;
}
.board-surface { line-height: 0; }

/* ----- Player strips ----- */
.player-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  width: 100%;
  padding: var(--s2) var(--s3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast);
}
.player-selector-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  flex: 1;
  min-width: 0;
}
.player-controls {
  display: flex;
  flex-direction: row;
  gap: var(--s1);
  width: 100%;
}
.player-controls .btn { flex: 1; }
.player-select {
  width: 100%;
  height: var(--input-h);
  padding: 0 var(--s3);
  font-size: 14px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.player-select:hover { border-color: var(--c-primary); }
.player-select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-soft); }

/* ----- Clock ----- */
.clock-compact {
  padding: var(--s1) var(--s3);
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  min-width: 88px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
  font-feature-settings: 'tnum';
}
.clock-compact.active { border-color: var(--c-primary); background: var(--c-primary); box-shadow: 0 1px 3px rgba(13,138,122,.3); }
.clock-compact.active .clock-time { color: #fff; }
.clock-compact.time-low { border-color: var(--c-accent); background: var(--c-accent-soft); }
.clock-compact.time-critical { border-color: var(--c-danger); background: #fdecec; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 8px rgba(214,59,59,.4);} 50% { box-shadow: 0 0 16px rgba(214,59,59,.7);} }
.clock-time { font-family: var(--mono); font-size: 22px; font-weight: 700; letter-spacing: 1px; color: var(--c-text); font-feature-settings: 'tnum'; }

/* ----- Board toolbar ----- */
.board-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  padding: var(--s2);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}
.toolbar-sep { flex: 1; }

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: var(--btn-h);
  padding: 0 var(--s4);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--c-primary);
  cursor: pointer;
  transition: background var(--t-fast), transform .04s, box-shadow var(--t-fast);
  width: auto;
  margin: 0;
  white-space: nowrap;
}
.btn:hover { background: var(--c-primary-hover); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--c-focus-ring); outline-offset: 2px; }
.btn-sm { height: var(--btn-h-sm); font-size: 13px; padding: 0 var(--s3); }
.btn-block { width: 100%; }
.btn-primary { background: var(--c-primary); }
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-success { background: var(--c-success); }
.btn-success:hover { background: var(--c-success-hover); }
.btn-danger { background: var(--c-danger); }
.btn-danger:hover { background: var(--c-danger-hover); }
.btn-neutral { background: var(--c-neutral); color: var(--c-neutral-text); }
.btn-neutral:hover { background: var(--c-neutral-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--btn-h-sm);
  width: var(--btn-h-sm);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text-soft);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--c-neutral); color: var(--c-text); }
.icon-btn:focus-visible { outline: 2px solid var(--c-focus-ring); outline-offset: 1px; }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ----- Inspector ----- */
.inspector {
  display: flex;
  flex-direction: column;
  flex: 1 1 360px;
  min-width: 0;
  max-width: 430px;
  background: var(--c-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
}
.tabbar {
  display: flex;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  position: relative;
}
.tab {
  flex: 1;
  height: 40px;
  padding: 0 var(--s3);
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-soft);
  cursor: pointer;
  transition: color var(--t-fast);
  position: relative;
}
.tab:hover { color: var(--c-text); }
.tab.is-active { color: var(--c-primary); }
.tab.is-active::after {
  content: '';
  position: absolute;
  left: var(--s4); right: var(--s4); bottom: -1px;
  height: 2px;
  background: var(--c-primary);
  border-radius: 2px 2px 0 0;
  animation: tabslide .18s ease;
}
@keyframes tabslide { from { transform: scaleX(.4); opacity: 0; } to { transform: scaleX(1); opacity: 1; } }
.inspector-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.tabpanel { display: flex; flex-direction: column; gap: var(--s3); }
.tabpanel[hidden] { display: none; }

/* ----- Panel sections ----- */
.panel-section { display: flex; flex-direction: column; gap: var(--s2); }
.panel-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-soft);
}
.field { display: flex; flex-direction: column; gap: var(--s1); }
.field-label { font-size: 12px; font-weight: 600; color: var(--c-text-soft); }
.field-select, .field-input {
  width: 100%;
  height: var(--input-h);
  padding: 0 var(--s3);
  font-size: 14px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field-select:hover, .field-input:hover { border-color: var(--c-primary); }
.field-select:focus, .field-input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-soft); }

/* ----- Info / opening ----- */
.info {
  padding: var(--s3);
  background: var(--c-surface-2);
  border-radius: var(--r-sm);
  text-align: center;
  color: var(--c-text-soft);
  font-size: 13px;
}
.opening-compact {
  padding: var(--s2) var(--s3);
  background: var(--c-accent-soft);
  border-left: 3px solid var(--c-accent);
  border-radius: var(--r-sm);
  font-size: 13px;
  line-height: 1.4;
}
.opening-label { font-weight: 700; color: var(--c-text-soft); margin-right: var(--s2); }
.opening-compact #openingText { color: var(--c-text); font-weight: 600; }

/* ----- History tab ----- */
.history-toolbar { display: flex; align-items: center; justify-content: center; }
.nav-group { display: flex; align-items: center; gap: var(--s1); }
.position-indicator {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text-soft);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 2px var(--s2);
  min-width: 48px;
  text-align: center;
}
.move-history { display: flex; flex-direction: column; gap: var(--s2); flex: 1; min-height: 0; }
.move-history-footer { display: none; }
.move-history-text {
  width: 100%;
  flex: 1;
  min-height: 200px;
  padding: var(--s3);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  color: var(--c-text);
  resize: none;
  overflow-y: auto;
}
.move-history-text:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-soft); }
.move-history-text::placeholder { color: var(--c-text-muted); }
.history-empty {
  padding: var(--s5) var(--s3);
  text-align: center;
  color: var(--c-text-muted);
  font-size: 13px;
  border: 1px dashed var(--c-border-strong);
  border-radius: var(--r-sm);
}

/* ----- Eval graph ----- */
.eval-graph-container {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: var(--s1);
  position: relative;
  min-height: 64px;
  flex-shrink: 0;
}
#evalGraph { width: 100%; height: 56px; cursor: pointer; display: block; border-radius: var(--r-sm); }
.eval-graph-score { position: absolute; top: 4px; right: 6px; font-size: 11px; font-weight: 700; padding: 1px 5px; border-radius: 3px; background: rgba(255,255,255,.92); color: var(--c-text); }

/* ----- Variants ----- */
.variant-controls-bottom { display: flex; flex-direction: column; gap: var(--s2); flex-shrink: 0; }
.variant-mode-controls { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); margin-top: var(--s2); }

/* ----- Analysis tab ----- */
.analysis-depth { opacity: .75; font-size: 12px; margin-left: var(--s1); }
.analysis-display-options { display: flex; flex-direction: column; gap: var(--s2); }
.analysis-option {
  display: flex;
  align-items: center;
  gap: var(--s2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  user-select: none;
  padding: var(--s1) var(--s2);
  border-radius: var(--r-sm);
  transition: background var(--t-fast);
}
.analysis-option:hover { background: var(--c-surface-2); }
.analysis-option input[type="radio"] { width: 16px; height: 16px; accent-color: var(--c-primary); cursor: pointer; flex-shrink: 0; }

/* ----- Position & Files dialog (<dialog>) ----- */
.position-dialog {
  width: min(520px, 92vw);
  max-height: 85vh;
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  background: var(--c-surface);
  color: var(--c-text);
  overflow: hidden;
}
.position-dialog::backdrop { background: rgba(15,23,42,.45); }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--c-border);
}
.dialog-title { font-size: 15px; font-weight: 700; }
.dialog-body-content { padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); overflow-y: auto; }
.dialog-section { display: flex; flex-direction: column; gap: var(--s2); }
.dialog-section-title { font-size: 12px; font-weight: 600; color: var(--c-text-soft); }
.dialog-divider { border: none; border-top: 1px solid var(--c-border); margin: 0; }
.dialog-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; }
.fen-hint { font-size: 12px; color: var(--c-text-muted); }
.pgn-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.pgn-actions .btn { width: 100%; }

/* ----- Custom dialog (existing) ----- */
.custom-dialog {
  position: fixed; z-index: 2000; inset: 0;
  background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .15s;
}
.dialog-content {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  width: 90%; max-width: 420px;
  overflow: hidden;
  animation: dialogIn .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes dialogIn { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.dialog-header { padding: var(--s5) var(--s5) var(--s2); text-align: center; }
.dialog-icon { font-size: 48px; line-height: 1; display: block; }
.dialog-body { padding: var(--s3) var(--s5) var(--s5); text-align: center; }
.dialog-message { font-size: 16px; color: #545454; line-height: 1.5; }
.dialog-footer { padding: 0 var(--s5) var(--s5); display: flex; justify-content: center; gap: var(--s2); }
.dialog-btn { padding: 10px var(--s5); border: none; border-radius: var(--r-sm); font-size: 15px; font-weight: 600; cursor: pointer; min-width: 110px; transition: background var(--t-fast); }
.dialog-btn-ok { background: var(--c-primary); color: #fff; }
.dialog-btn-ok:hover { background: var(--c-primary-hover); }
.dialog-btn-cancel { background: var(--c-neutral); color: var(--c-neutral-text); }
.dialog-btn-cancel:hover { background: var(--c-neutral-hover); }

/* ----- Modal (existing PGN selector) ----- */
.modal {
  position: fixed; z-index: 1000; inset: 0;
  overflow: auto;
  background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .3s;
}
.modal-content {
  background: var(--c-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  width: 90%; max-width: 1000px; max-height: 90vh;
  display: flex; flex-direction: column;
}
.modal-header {
  padding: var(--s4) var(--s5);
  background: var(--c-primary);
  color: #fff;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h2 { font-size: 18px; color: #fff; }
.modal-close { color: #fff; font-size: 28px; font-weight: 700; cursor: pointer; line-height: 1; padding: 0 4px; }
.modal-close:hover { color: #ffeb3b; }
.modal-body { padding: var(--s5); overflow-y: auto; flex: 1; }
.modal-info { margin-bottom: var(--s4); font-size: 15px; color: var(--c-text-soft); }
.modal-footer { padding: var(--s3) var(--s5); background: var(--c-surface-2); border-top: 1px solid var(--c-border); border-radius: 0 0 var(--r-lg) var(--r-lg); display: flex; justify-content: flex-end; gap: var(--s2); }
.modal-btn { padding: 8px var(--s4); border: none; border-radius: var(--r-sm); font-size: 14px; font-weight: 600; cursor: pointer; transition: background var(--t-fast); }
.modal-btn-cancel { background: var(--c-neutral); color: var(--c-neutral-text); }
.modal-btn-cancel:hover { background: var(--c-neutral-hover); }

/* ----- Game table ----- */
.game-table-container { max-height: 500px; overflow: auto; border: 1px solid var(--c-border); border-radius: var(--r-sm); }
.game-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.game-table thead { position: sticky; top: 0; background: var(--c-primary); color: #fff; z-index: 10; }
.game-table th { padding: var(--s3); text-align: left; font-weight: 600; }
.game-table th:first-child { width: 50px; text-align: center; }
.game-table tbody tr { cursor: pointer; border-bottom: 1px solid var(--c-border); transition: background var(--t-fast); }
.game-table tbody tr:hover { background: var(--c-primary-soft); }
.game-table td { padding: var(--s3); color: var(--c-text); }
.game-table td:first-child { text-align: center; font-weight: 700; color: var(--c-primary); }

/* ----- Loading bar ----- */
.opening-loading-bar { margin-bottom: var(--s3); padding: var(--s3); background: var(--c-primary-soft); border: 1px solid var(--c-primary); border-radius: var(--r-sm); }
.loading-bar-text { font-size: 13px; color: var(--c-primary); font-weight: 600; margin-bottom: var(--s2); text-align: center; }
.loading-bar-container { height: 8px; background: #d8e3fb; border-radius: 4px; overflow: hidden; }
.loading-bar-fill { height: 100%; background: var(--c-primary); border-radius: 4px; transition: width .3s ease; width: 0%; }

/* ----- CodeMirror ----- */
.CodeMirror { height: 100% !important; font-family: var(--mono); font-size: 13px; line-height: 1.7; border: 1px solid var(--c-border-strong); border-radius: var(--r-sm); background: var(--c-surface-2); flex: 1; min-height: 200px; }
.CodeMirror-scroll { max-height: 100%; overflow-y: auto !important; }
.CodeMirror-lines { padding: var(--s3); }
.cm-chess-move-number { color: var(--c-text); font-weight: 900; }
.cm-chess-move { color: var(--c-text); font-weight: 700; }
.cm-chess-check { color: #ff6b35; font-weight: 700; }
.cm-chess-checkmate { color: var(--c-danger); font-weight: 700; }
.cm-chess-promotion { color: #7e57c2; font-weight: 600; }
.cm-chess-result { color: var(--c-text-soft); font-weight: 600; font-style: italic; }
.cm-chess-annotation { color: #1976d2; font-weight: 600; }
.cm-chess-comment { color: var(--c-success); font-style: italic; }
.cm-chess-variation { color: #9c27b0; }
.cm-chess-nag { color: var(--c-accent); font-size: 11px; }
.chess-current-move, .chess-selected-variant { background: var(--c-primary); color: #fff; border-radius: 2px; font-weight: 700; box-shadow: 0 0 4px rgba(47,111,237,.5); }
.chess-future-move { opacity: .4; }

/* ----- Ghost pieces ----- */
.ghost-piece { opacity: .5 !important; pointer-events: none; z-index: 100; position: absolute; transition: opacity .2s ease-in-out; }
.ghost-piece.ghost-fade-in { animation: ghostIn .3s ease-in-out; }
.ghost-piece.ghost-fade-out { animation: ghostOut .3s ease-in-out; }
@keyframes ghostIn { from { opacity: 0; } to { opacity: .5; } }
@keyframes ghostOut { from { opacity: .5; } to { opacity: 0; } }

/* =========================================================
   Responsive
   ========================================================= */

/* Wide desktop: board sizes up */
@media (min-width: 1200px) {
  #myBoard { width: 600px; max-width: 600px; }
  .player-info { width: 600px; max-width: 600px; }
  .board-toolbar { width: 600px; max-width: 600px; }
}

/* Extra wide: a touch more */
@media (min-width: 1440px) {
  .app { max-width: 1360px; }
  #myBoard { width: 640px; max-width: 640px; }
  .player-info { width: 640px; max-width: 640px; }
  .board-toolbar { width: 640px; max-width: 640px; }
}

/* Laptop: shrink board, keep two columns */
@media (max-width: 1199px) and (min-width: 1024px) {
  #myBoard { width: 520px; max-width: 520px; }
  .player-info { width: 520px; max-width: 520px; }
  .board-toolbar { width: 520px; max-width: 520px; }
  .inspector { max-width: 380px; }
}

/* Tablet / narrow: stack, allow page scroll */
@media (max-width: 1023px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .app-main { flex-direction: column; overflow: visible; }
  .board-workspace { width: 100%; }
  #myBoard { width: 100%; max-width: 540px; }
  .player-info, .board-toolbar { width: 100%; max-width: 540px; }
  .inspector { max-width: 540px; width: 100%; max-height: 70vh; }
}

/* Mobile */
@media (max-width: 600px) {
  .app-main { padding: var(--s2); gap: var(--s2); }
  .app-header { padding: 0 var(--s2); }
  .app-title { font-size: 14px; }
  .header-status { font-size: 12px; }
  .clock-time { font-size: 18px; }
  .clock-compact { min-width: 76px; }
  .player-info { padding: var(--s1) var(--s2); gap: var(--s2); flex-wrap: wrap; }
  .inspector { max-height: none; }
  .inspector-body { padding: var(--s2); }
  .move-history-text { min-height: 160px; }
}

/* Landscape mobile: keep board + inspector side-by-side if room */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .app-main { flex-direction: row; }
  #myBoard { width: 340px; max-width: 340px; }
  .player-info, .board-toolbar { width: 340px; max-width: 340px; }
  .inspector { flex: 1 1 280px; min-width: 240px; max-height: none; }
}
