/* Chess Coach — mobile-first */
:root {
  --bg: #191e2c;
  --panel: #232a3d;
  --panel2: #2c3550;
  --text: #e8ebf4;
  --muted: #9aa3bc;
  --accent: #4f8cff;
  --accent2: #37c978;
  --warn: #ffb454;
  --danger: #ff6b6b;
  --sq-light: #eed7b0;
  --sq-dark: #b58863;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.view {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
.view.active { display: flex; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: 1.05rem; }
.badge {
  background: var(--panel2);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: .85rem;
  color: var(--muted);
}
.badge.mine { background: var(--accent2); color: #06301a; font-weight: 700; }
.badge.theirs { background: var(--warn); color: #4a2d00; font-weight: 700; }

/* Board */
.board-wrap { padding: 0 8px; }
#board {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  touch-action: manipulation;
}

/* Coach panel */
.coach {
  margin: 12px;
  background: var(--panel);
  border-radius: 14px;
  padding: 14px;
  min-height: 76px;
}
.coach-main { font-size: 1.05rem; font-weight: 650; line-height: 1.35; }
.coach-details { margin-top: 6px; color: var(--muted); font-size: .92rem; line-height: 1.4; }
.coach-warnings { margin-top: 8px; color: var(--warn); font-size: .92rem; line-height: 1.4; }
.coach-warnings:empty, .coach-details:empty { display: none; }

/* Actions */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 12px 8px;
}
.secondary-actions { margin-top: auto; }

.btn {
  flex: 1 1 auto;
  border: none;
  border-radius: 12px;
  background: var(--panel2);
  color: var(--text);
  font-size: .95rem;
  font-weight: 600;
  padding: 12px 14px;
  cursor: pointer;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 8px 10px; font-size: .85rem; flex: 0 1 auto; }
.btn.big { padding: 16px; font-size: 1.1rem; }
.hidden { display: none !important; }

/* Editor */
.editor-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  z-index: 30;
  box-shadow: 0 -6px 30px rgba(0,0,0,.5);
}
.editor-palette { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 8px; }
.editor-palette button {
  width: 44px; height: 44px;
  font-size: 28px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--panel2);
  color: var(--text);
}
.editor-palette button.sel { border-color: var(--accent); }
.editor-row { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 8px; font-size: .9rem; }
.editor-row select { background: var(--panel2); color: var(--text); border: none; border-radius: 8px; padding: 6px; }
.editor-error { color: var(--danger); text-align: center; font-size: .85rem; margin-top: 6px; }

/* Camera */
.cam-stage {
  position: relative;
  margin: 0 8px;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 3/4;
}
#cam-video, #cam-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
#cam-canvas { object-fit: contain; background: #000; }
.cam-overlay { position: absolute; inset: 0; pointer-events: none; }
.cam-overlay .corner-dot {
  position: absolute;
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 8px rgba(0,0,0,.6);
}
.cam-hint {
  margin: 10px 16px;
  color: var(--muted);
  font-size: .92rem;
  text-align: center;
  line-height: 1.4;
  min-height: 2.6em;
}
.cam-hint.busy { color: var(--accent); }
.cam-hint.error { color: var(--danger); }

.candidates { padding: 0 12px; display: flex; flex-direction: column; gap: 8px; }
.candidates .cand {
  background: var(--panel);
  border: 2px solid transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 12px;
  text-align: left;
  font-size: 1rem;
}
.candidates .cand strong { color: var(--accent2); }
.candidates .cand:first-child { border-color: var(--accent2); }

/* Settings */
.settings { padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }
fieldset { border: 1px solid var(--panel2); border-radius: 12px; padding: 12px; }
legend { padding: 0 6px; color: var(--muted); font-size: .85rem; }
.settings label { display: block; margin: 10px 0; font-size: .92rem; color: var(--muted); }
.settings input[type=text], .settings input[type=password], .settings select {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--panel2);
  border: none;
  border-radius: 10px;
  color: var(--text);
  padding: 10px;
  font-size: 1rem;
}
.settings label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.settings label.check input { width: 20px; height: 20px; }
.note { color: var(--muted); font-size: .82rem; line-height: 1.4; margin-top: 6px; }

/* Modals */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 24px;
}
.modal-box {
  background: var(--panel);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 380px;
  display: flex; flex-direction: column; gap: 14px;
}
.promo-choices { display: flex; flex-direction: column; gap: 8px; }

/* Tab bar */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--panel2);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.3rem;
  padding: 8px 0 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: .68rem; font-weight: 600; }
.tab.active { color: var(--accent); }

/* Board SVG bits */
.sq-light { fill: var(--sq-light); }
.sq-dark { fill: var(--sq-dark); }
.sq-sel { fill: rgba(79,140,255,.55); }
.sq-target { fill: rgba(55,201,120,.5); }
.sq-last { fill: rgba(255,214,90,.45); }
.piece { font-size: 78px; text-anchor: middle; pointer-events: none; user-select: none; }
.coord { font-size: 20px; fill: rgba(0,0,0,.45); font-weight: 700; pointer-events: none; }
.arrow { fill: none; stroke: var(--accent2); stroke-width: 16; stroke-linecap: round; opacity: .85; }
.arrow-head { fill: var(--accent2); opacity: .85; }
