/* ChessClass — editorial chess-club design system */

:root {
  --paper: #f4f1ea;
  --paper-2: #efeade;
  --surface: #fffdf8;
  --ink: #16130f;
  --ink-soft: #4b443a;
  --muted: #736b5e;
  --line: #ded6c7;
  --line-strong: #c9bfab;
  --accent: #1c4d3f;
  --accent-hover: #163d32;
  --accent-soft: #e6ece4;
  --claret: #8c2f2f;
  --ok: #2f6b4f;
  --warn: #8a6218;
  --sq-light: #e9dec7;
  --sq-dark: #8d6f4e;
  --mark: #1f6f57;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { flex: 1; display: flex; flex-direction: column; min-height: 0; }

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: #cfe0d3; }

.icon { flex: none; display: block; }

/* ---------- primitives ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  cursor: pointer;
  transition: background .14s ease, border-color .14s ease, color .14s ease;
  white-space: nowrap;
}
.btn:hover { background: #fff; border-color: var(--ink-soft); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fdfcf7; font-weight: 500; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 8px; }
.btn.ghost:hover { background: transparent; color: var(--ink); text-decoration: underline; }
.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn.small.ghost { padding: 4px 6px; }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 7px; }
.field label, .label {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted);
}
input[type="text"], input[type="search"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
}
input[type="text"]:focus, input[type="search"]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(28, 77, 63, .12);
}
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

/* ---------- masthead ---------- */
.site-head {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.site-head-inner {
  max-width: 1160px; margin: 0 auto; padding: 18px 32px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.wordmark { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 19px; letter-spacing: -.01em; }
.wordmark .mark {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 1px solid var(--line-strong); border-radius: 3px;
  background: var(--surface); font-size: 16px; line-height: 1;
}
.site-head .head-link {
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted);
}
.site-head .head-link:hover { color: var(--accent); text-decoration: none; }

/* ---------- landing ---------- */
.landing {
  width: 100%; max-width: 1160px; margin: 0 auto; padding: 60px 32px 48px;
  display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(300px, 380px);
  gap: 60px; align-items: start; flex: 1;
}
.kicker {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .2em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 20px;
}
.hero-title {
  font-family: var(--serif); font-weight: 500; font-size: clamp(32px, 4.2vw, 48px);
  line-height: 1.06; letter-spacing: -.018em; margin: 0 0 20px;
}
.hero-title em { font-style: italic; color: var(--accent); }
.hero-sub { font-size: 15.5px; line-height: 1.65; color: var(--ink-soft); max-width: 54ch; margin: 0; }

.spec-list { list-style: none; margin: 36px 0 0; padding: 0; border-top: 1px solid var(--line); }
.spec-list li {
  display: grid; grid-template-columns: 128px 1fr; gap: 20px;
  padding: 15px 0; border-bottom: 1px solid var(--line);
  font-size: 13.5px; line-height: 1.55; color: var(--ink-soft);
}
.spec-list b { font-weight: 600; color: var(--ink); }

.panel { border-left: 1px solid var(--line); padding-left: 36px; }
.panel h2 { font-family: var(--serif); font-size: 18px; font-weight: 600; margin: 0 0 6px; letter-spacing: -.01em; }
.panel p { font-size: 13px; line-height: 1.6; color: var(--muted); margin: 0 0 16px; }
.panel .rule { height: 1px; background: var(--line); margin: 28px 0; }
.panel .btn { width: 100%; }

.site-foot {
  border-top: 1px solid var(--line); margin-top: 8px; padding: 18px 32px 28px;
  font-size: 12px; color: var(--muted);
}
.site-foot-inner {
  max-width: 1160px; margin: 0 auto;
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}

@media (max-width: 900px) {
  .landing { grid-template-columns: 1fr; gap: 34px; padding: 34px 20px 32px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); padding-left: 0; padding-top: 30px; }
  .site-head { padding: 14px 20px; }
  .site-foot { padding: 16px 20px 24px; }
  .spec-list li { grid-template-columns: 1fr; gap: 2px; }
}

/* ---------- shell ---------- */
.shell { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.student-shell { display: grid; grid-template-rows: auto 1fr; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; margin: 0; }
.topbar .brand-mark {
  width: 26px; height: 26px; display: grid; place-items: center;
  border: 1px solid var(--line-strong); border-radius: 3px; background: var(--paper);
  font-size: 15px; line-height: 1;
}
.topbar .brand h1 { font-family: var(--serif); font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.topbar .brand small { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }
.topbar .spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px; border: 1px solid var(--line); border-radius: 3px;
  background: var(--paper); font-size: 11.5px; color: var(--muted);
}
.chip b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.live { border-color: rgba(140, 47, 47, .3); color: var(--claret); }
.chip.live b { color: var(--claret); }
.score-pill { font-variant-numeric: tabular-nums; }

.code-pill {
  font-family: var(--mono); font-size: 13.5px; letter-spacing: .16em;
  background: var(--ink); color: #f7f3e9; border: 0; border-radius: 3px;
  padding: 7px 12px; cursor: pointer;
}
.code-pill:hover { background: #2a251d; }

.studio {
  display: grid; grid-template-columns: minmax(320px, 1fr) 392px;
  gap: 26px; padding: 24px; overflow: hidden;
}
.board-column { display: flex; flex-direction: column; gap: 14px; min-width: 0; align-items: center; }
.student-board { width: 100%; display: flex; justify-content: center; }

/* ---------- board ---------- */
.board-wrap {
  position: relative;
  width: min(100%, calc(100vh - 250px), 640px);
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 20px 40px -30px rgba(22, 19, 15, .55);
  user-select: none;
  touch-action: none;
}
.board-grid {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
}
.sq { position: relative; display: grid; place-items: center; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq .piece {
  font-family: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols 2", var(--sans);
  font-size: min(9vw, 58px);
  line-height: 1;
  pointer-events: none;
}
.sq .piece.w { color: #fffdf7; text-shadow: 0 1px 0 #7a6247, 0 0 1px #5c4832, 0 2px 3px rgba(22, 19, 15, .35); }
.sq .piece.b { color: #191510; text-shadow: 0 1px 0 rgba(255, 255, 255, .22), 0 2px 3px rgba(22, 19, 15, .25); }
.sq.last::after { content: ""; position: absolute; inset: 0; background: rgba(197, 160, 66, .34); }
.sq.sel::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px var(--mark); }
.sq.target::before {
  content: ""; position: absolute; width: 20%; height: 20%; border-radius: 50%;
  background: rgba(22, 19, 15, .28);
}
.sq.check::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(140, 47, 47, .78), rgba(140, 47, 47, .06) 72%);
}
.sq .coord { position: absolute; font-family: var(--mono); font-size: 9px; font-weight: 600; opacity: .5; color: #4b3a24; }
.sq.dark .coord { color: #f6eddb; opacity: .55; }
.sq .coord.file { right: 4px; bottom: 2px; }
.sq .coord.rank { left: 4px; top: 2px; }

.marks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.board-tools { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.board-tools .btn { padding: 6px 10px; font-size: 12px; border-color: transparent; background: transparent; color: var(--ink-soft); }
.board-tools .btn:hover { background: var(--surface); border-color: var(--line); }
.board-tools .btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.palette { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.palette button {
  width: 38px; height: 38px; border-radius: 3px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 21px; line-height: 1;
  display: grid; place-items: center;
}
.palette button:hover { border-color: var(--line-strong); }
.palette button.on { border-color: var(--accent); background: var(--accent-soft); }
.palette button.w { color: #fff; text-shadow: 0 0 1px #6d5942, 0 1px 1px rgba(0, 0, 0, .5); }
.palette button.b { color: #191510; }

.lesson-strip { display: flex; align-items: center; gap: 8px; width: 100%; max-width: 640px; justify-content: center; }

/* ---------- side panel ---------- */
.side {
  display: grid; grid-template-rows: auto 1fr; min-height: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 3px;
  overflow: hidden;
}
.tabs {
  display: flex; border-bottom: 1px solid var(--line); overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 1 1 auto; padding: 11px 4px; background: none; border: 0; border-bottom: 2px solid transparent;
  font-family: var(--mono); font-size: 9px; letter-spacing: .03em; text-transform: uppercase;
  color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.tab-body { padding: 16px; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 12px; }

.section-title {
  font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin: 6px 0 0;
}

.student-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.student-row:last-child { border-bottom: 0; }
.student-row .name { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13.5px; }
.student-row .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence { width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); flex: none; }
.presence.on { background: var(--ok); }
.hand { color: var(--warn); display: inline-flex; }

select.status {
  padding: 4px 22px 4px 7px; font-size: 11.5px; border-radius: 3px; width: auto;
  background-position: calc(100% - 12px) 52%, calc(100% - 7px) 52%;
}
.status-present { color: var(--ok); }
.status-late { color: var(--warn); }
.status-absent { color: var(--claret); }
.status-excused { color: var(--muted); }

.lesson-item {
  padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.lesson-item:hover .lesson-name { color: var(--accent); text-decoration: underline; }
.lesson-item.on .lesson-name { color: var(--accent); font-weight: 600; }
.lesson-item .lesson-name { font-size: 13.5px; }
.lesson-item small { color: var(--muted); font-size: 11.5px; display: block; margin-top: 2px; line-height: 1.45; }

.chat-log { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; flex: 1; min-height: 120px; }
.msg { font-size: 13px; line-height: 1.5; }
.msg b { font-weight: 600; color: var(--ink); }
.msg.teacher b { color: var(--accent); }
.msg .time { font-family: var(--mono); color: var(--muted); font-size: 10px; margin-left: 7px; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; }

.badge {
  font-family: var(--mono); font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 2px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge.amber { color: var(--warn); border-color: rgba(138, 98, 24, .35); background: #fbf3e0; }
.badge.green { color: var(--ok); border-color: rgba(47, 107, 79, .35); background: #edf4ee; }
.badge.red { color: var(--claret); border-color: rgba(140, 47, 47, .3); background: #fbeeee; }

.notice {
  padding: 11px 13px; border: 1px solid var(--line); border-left: 2px solid var(--line-strong);
  background: var(--paper); font-size: 12.5px; line-height: 1.55; color: var(--ink-soft);
}
.notice.amber { border-left-color: var(--accent); background: var(--accent-soft); color: #22453a; }
.notice .code-line { font-family: var(--mono); font-size: 11.5px; word-break: break-all; user-select: all; margin: 6px 0 10px; color: var(--ink); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: #f8f4ea; padding: 10px 16px; border-radius: 3px;
  font-size: 12.5px; opacity: 0; transition: opacity .16s ease, transform .16s ease;
  pointer-events: none; z-index: 60; max-width: min(90vw, 460px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- student ---------- */
.student-main {
  display: grid; grid-template-columns: minmax(300px, 1fr) 330px;
  gap: 22px; padding: 20px; overflow: hidden;
}
.quiz-banner {
  border: 1px solid var(--line-strong); border-left: 3px solid var(--accent);
  background: var(--surface); padding: 12px 14px; font-size: 13px; color: var(--ink-soft);
  width: 100%; max-width: 640px;
}
.quiz-banner b { display: block; font-family: var(--serif); font-size: 15px; color: var(--ink); margin-bottom: 3px; }

/* ---------- join ---------- */
.join-wrap { min-height: 100vh; display: grid; place-items: center; padding: 32px 20px; }
.join-card {
  width: min(420px, 100%); background: var(--surface);
  border: 1px solid var(--line); border-radius: 3px; padding: 30px 28px;
  display: grid; gap: 16px;
}
.join-card .wordmark { margin-bottom: 2px; }
.join-card h2 { font-family: var(--serif); font-size: 22px; font-weight: 500; margin: 6px 0 0; letter-spacing: -.01em; }
.code-input {
  font-family: var(--mono); font-size: 24px; letter-spacing: .3em; text-align: center;
  padding: 14px 8px; text-indent: .3em;
}
.error { color: var(--claret); font-size: 12.5px; min-height: 18px; line-height: 1.45; }

.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.tiny { font-size: 11.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

@media (max-width: 980px) {
  .studio { grid-template-columns: 1fr; overflow: auto; }
  .student-main { grid-template-columns: 1fr; overflow: auto; }
}

/* ---------- media ---------- */
.media-controls { display: flex; gap: 6px; align-items: center; }
.btn.icon-btn { width: 32px; height: 32px; padding: 0; border-radius: 3px; color: var(--ink-soft); }
.btn.icon-btn.on { background: var(--accent); border-color: var(--accent); color: #fdfcf7; }

.media-strip {
  display: flex; gap: 8px; width: 100%; max-width: 640px; justify-content: center;
  overflow: auto hidden; padding-bottom: 2px; min-height: 0;
}
.media-strip:empty { display: none; }
.media-tile {
  position: relative; flex: none; width: 104px; height: 72px;
  border: 1px solid var(--line); background: var(--paper-2); border-radius: 3px; overflow: hidden;
}
.media-tile.live { background: #14110d; }
.media-tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #14110d; }
.media-tile.self video { transform: scaleX(-1); }
.media-tile.live { border-color: var(--line-strong); }
.media-fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--serif); font-size: 15px; color: var(--muted); letter-spacing: .04em;
}
.media-tile.live .media-fallback { color: #c3b7a2; }
.media-tile.live .media-fallback { display: none; }
.media-tile.live video { display: block; }
.media-tile:not(.live) video { display: none; }
.media-cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  padding: 3px 5px; font-size: 10px; color: var(--ink-soft); background: none;
}
.media-tile.live .media-cap {
  color: #f6f2e8;
  background: linear-gradient(to top, rgba(16, 13, 10, .78), rgba(16, 13, 10, 0));
}
.media-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-flag { display: inline-flex; opacity: .9; }
.media-flag.off { color: #e8a1a1; }

/* ---------- leaderboard ---------- */
.rank-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.rank-row:last-child { border-bottom: 0; }
.rank-num { font-family: var(--mono); font-size: 11px; color: var(--muted); width: 14px; }

/* ---------- puzzle library ---------- */
.puzzle-list { display: flex; flex-direction: column; max-height: 300px; overflow: auto; border-top: 1px solid var(--line); }
.puzzle-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 7px 2px; border: 0; border-bottom: 1px solid var(--line);
  background: none; cursor: pointer; text-align: left; font: inherit;
}
.puzzle-item:hover { background: var(--paper); }
.puzzle-item.on { background: var(--accent-soft); }
.puzzle-item .mono { font-size: 12.5px; }

/* ---------- presentation ---------- */
body.present .side { display: none; }
body.present .studio { grid-template-columns: 1fr; }
body.present .board-wrap { width: min(100%, calc(100vh - 190px), 880px); }
body.present .topbar .btn.ghost { display: none; }


/* ---------- phones ---------- */
.shell, .student-shell { height: 100vh; height: 100dvh; }

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; padding: 9px 12px; gap: 8px; }
  .topbar .brand small { display: none; }
  .topbar .brand h1 { font-size: 14px; }
  .topbar .btn { padding: 6px 9px; font-size: 12px; }
  .topbar .btn.icon-btn { width: 30px; height: 30px; }
  .code-pill { font-size: 12px; padding: 6px 9px; letter-spacing: .1em; }
  .chip { font-size: 10.5px; padding: 4px 7px; }

  .studio, .student-main { padding: 12px; gap: 14px; }
  .board-column { gap: 10px; }
  .board-wrap { width: 100%; box-shadow: none; }
  .board-tools .btn { padding: 6px 8px; font-size: 11.5px; }
  .media-tile { width: 84px; height: 60px; }
  .media-strip { max-width: 100%; }

  .side { min-height: 380px; }
  .tab-body { padding: 12px; }
  .tabs button { font-size: 9.5px; letter-spacing: .06em; padding: 9px 4px; }
  .lesson-strip { flex-wrap: wrap; }
  .site-foot-inner { justify-content: flex-start; }
}
