/* ---------------------------------------------------------------------------
   Shogi for Blood — Design System Styles
   --------------------------------------------------------------------------- */

/* ── Tokens ── */
:root {
  --blood: #B01C1C;
  --blood-light: #F5E0E0;
  --blood-dark: #7A0E0E;
  --ink: #1A1917;
  --ink-mid: #3D3C39;
  --ink-muted: #6B6A66;
  --wood: #C8933A;
  --wood-light: #F5ECD8;
  --wood-dark: #8A6120;
  --ivory: #FAF8F3;
  --ivory-mid: #F0EDE4;
  --ivory-border: #DDD9CC;
  --white: #FFFFFF;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font: 'Georgia', 'Times New Roman', serif;
  --font-sans: system-ui, -apple-system, sans-serif;
  --font-mono: 'Menlo', 'Courier New', monospace;
}

/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--ivory);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--blood-dark); }
a:hover { color: var(--blood); }

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font);
  line-height: 1.2;
  letter-spacing: 0.01em;
  color: var(--ink);
  margin: 0 0 1rem;
}

h1 { font-size: clamp(2rem, 5vw, 3.4rem); font-weight: 400; }
h2 { font-size: clamp(1.4rem, 3vw, 1.8rem); font-weight: 400; }
h4 { font-size: 1.1rem; }

p,
ul,
ol {
  margin-top: 0;
  margin-bottom: 1rem;
}

fieldset { border: none; padding: 0; margin: 0; }
legend {
  margin-bottom: 1.5rem;
  font-family: var(--font);
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--ink);
}

select, input, textarea, button { font: inherit; }
ul { padding-left: 1.25rem; }

/* ── Layout utilities ── */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box;
}

.row {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -15px;
}

.col-lg-4,
.col-lg-6,
.col-lg-8,
.col-lg-12 {
  padding: 0 15px;
  box-sizing: border-box;
  width: 100%;
}

@media (min-width: 768px) {
  .col-lg-4  { width: 33.333%; }
  .col-lg-6  { width: 50%; }
  .col-lg-8  { width: 66.666%; }
  .col-lg-12 { width: 100%; }
}

/* ── Site header ── */
.site-header {
  background: var(--ink);
  border-bottom: 0.5px solid rgba(255, 255, 255, 0.08);
  position: relative;
}

.site-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-wordmark {
  font-family: var(--font);
  font-size: 1.05rem;
  letter-spacing: .06em;
  color: var(--ivory);
  text-decoration: none;
}

.site-wordmark:hover { color: var(--ivory-mid); }

/* Desktop nav */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav a {
  font-size: 13px;
  color: rgba(250, 248, 243, 0.7);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  display: block;
}

.site-nav a:hover {
  color: var(--ivory);
  background: rgba(255, 255, 255, 0.08);
}

.nav-signout-btn {
  font-size: 13px;
  color: rgba(250, 248, 243, 0.7);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  display: block;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.nav-signout-btn:hover {
  color: var(--ivory);
  background: rgba(255, 255, 255, 0.08);
}

/* Hamburger toggle (hidden checkbox) */
.nav-toggle-checkbox {
  display: none;
}

/* Hamburger button — hidden on desktop */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.nav-hamburger span {
  display: block;
  height: 2px;
  background: rgba(250, 248, 243, 0.7);
  border-radius: 2px;
  transition: background 0.15s;
}

.nav-hamburger:hover span {
  background: var(--ivory);
}

/* Mobile drawer — hidden by default */
.site-nav-mobile {
  display: none;
  background: var(--ink);
  border-top: 0.5px solid rgba(255, 255, 255, 0.08);
  position: absolute;
  top: 52px;
  left: 0;
  right: 0;
  z-index: 100;
}

.site-nav-mobile ul {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0;
}

.site-nav-mobile a,
.site-nav-mobile .nav-signout-btn {
  display: block;
  padding: 10px 1.5rem;
  color: rgba(250, 248, 243, 0.8);
  text-decoration: none;
  font-size: 15px;
  font-family: inherit;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.site-nav-mobile a:hover,
.site-nav-mobile .nav-signout-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ivory);
}

/* ── Page content wrapper ── */
.page-content {
  max-width: 1120px;
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
}

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 1.2rem;
  font-size: 14px;
}

.alert-error {
  background: var(--blood-light);
  color: var(--blood-dark);
  border-left: 3px solid var(--blood);
}

.alert-success {
  background: var(--wood-light);
  color: var(--wood-dark);
  border-left: 3px solid var(--wood);
}

/* ── Typography utilities ── */
.t-display   { font-family: var(--font); font-size: 2.4rem; font-weight: 400; color: var(--ink); line-height: 1; }
.t-heading   { font-family: var(--font); font-size: 1.4rem; font-weight: 400; color: var(--ink); margin: 0 0 1rem; }
.t-subheading { font-family: var(--font-sans); font-size: 1rem; font-weight: 500; color: var(--ink); letter-spacing: .02em; }
.t-body      { font-family: var(--font-sans); font-size: .9375rem; color: var(--ink-mid); }
.t-caption   { font-family: var(--font-sans); font-size: .75rem; color: var(--ink-muted); letter-spacing: .04em; }
.t-mono      { font-family: var(--font-mono); font-size: .8125rem; color: var(--blood); }
.t-label     { font-family: var(--font-sans); font-size: .625rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-muted); }

/* ── Section label ── */
.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.75rem;
}

/* ── Eyebrow (kept for compat, same style as section-label) ── */
.eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.75rem;
}

/* ── Wordmark / hero ── */
.wordmark {
  font-family: var(--font);
  font-size: 13px;
  letter-spacing: .25em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.4rem;
}

h1.hero {
  font-family: var(--font);
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 400;
  line-height: 1.1;
  color: var(--ink);
}

h1.hero .accent { color: var(--blood); }

.hero-sub {
  font-size: 14px;
  color: var(--ink-muted);
  letter-spacing: .05em;
  margin: 0.8rem 0 1.5rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  height: 40px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all .15s ease;
  white-space: nowrap;
  user-select: none;
  text-align: center;
  vertical-align: middle;
}

.btn-primary         { background: var(--ink);        color: var(--ivory); }
.btn-primary:hover   { background: var(--ink-mid);    color: var(--ivory); }

.btn-danger          { background: var(--blood);      color: #fff; }
.btn-danger:hover    { background: var(--blood-dark); color: #fff; }

.btn-secondary       { background: transparent; color: var(--ink);     border: 0.5px solid var(--ivory-border); }
.btn-secondary:hover { background: var(--ivory-mid);  color: var(--ink); }

.btn-ghost           { background: transparent; color: var(--ink-muted); border: none; }
.btn-ghost:hover     { color: var(--ink); background: var(--ivory-mid); }

.btn-wood            { background: var(--wood);       color: var(--white); }
.btn-wood:hover      { background: var(--wood-dark);  color: var(--white); }

/* Legacy alias */
.btn-default         { background: transparent; color: var(--ink); border: 0.5px solid var(--ivory-border); }
.btn-default:hover   { background: var(--ivory-mid);  color: var(--ink); }

/* Pass button (was btn-warning) */
.btn-warning         { background: var(--ivory-mid);  color: var(--ink-mid); border: 0.5px solid var(--ivory-border); }
.btn-warning:hover   { background: var(--ivory-border); color: var(--ink); }

.btn-sm { height: 30px; padding: 0 12px; font-size: 11px; border-radius: var(--radius-sm); }
.btn-lg { height: 48px; padding: 0 28px; font-size: 15px; border-radius: var(--radius-md); }

.btn.disabled,
.btn[disabled] { opacity: .38; pointer-events: none; cursor: not-allowed; }

.btn-grid { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

/* ── Forms ── */
.form-group { margin-bottom: 1.2rem; }

label {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-control,
select,
textarea {
  display: block;
  width: 100%;
  padding: 0 14px;
  height: 40px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--ink);
  background: var(--white);
  border: 0.5px solid var(--ivory-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color .15s;
  appearance: none;
  box-sizing: border-box;
}

textarea,
.form-textarea {
  height: auto;
  padding: 12px 14px;
  resize: vertical;
}

.form-input:focus,
.form-select:focus,
.form-control:focus,
select:focus,
textarea:focus {
  border-color: var(--ink-mid);
  box-shadow: 0 0 0 3px rgba(26, 25, 23, .07);
}

.form-input::placeholder,
.form-textarea::placeholder,
.form-control::placeholder { color: var(--ink-muted); }

.form-hint      { font-size: 12px; color: var(--ink-muted); margin-top: 5px; }
.form-error-input { border-color: var(--blood); }
.form-error-msg { font-size: 12px; color: var(--blood); margin-top: 5px; }

.form-select-wrap { position: relative; }
.form-select-wrap::after {
  content: '';
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--ink-muted);
  pointer-events: none;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.radio,
.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  font-weight: normal;
  font-size: 14px;
  color: var(--ink-mid);
  text-transform: none;
  letter-spacing: 0;
}

.check-item { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--ink-mid); }
.check-item input[type=checkbox],
.check-item input[type=radio] { accent-color: var(--ink); width: 16px; height: 16px; cursor: pointer; margin: 0; }

/* form action rows */
.form-actions,
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 1.5rem;
}

/* ── Divider ── */
hr,
hr.divider {
  border: none;
  border-top: 0.5px solid var(--ivory-border);
  margin: 2.5rem 0;
}

/* ── Badges ── */
.badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 3px;
}
.badge-blood { background: var(--blood-light); color: var(--blood-dark); }
.badge-wood  { background: var(--wood-light);  color: var(--wood-dark); }
.badge-ink   { background: var(--ivory-mid);   color: var(--ink-mid); }

/* ── Cards ── */
.card {
  background: var(--white);
  border: 0.5px solid var(--ivory-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-body   { padding: 16px 18px; }
.card-meta   { font-size: 11px; color: var(--ink-muted); margin-bottom: 4px; letter-spacing: .04em; }
.card-title  { font-family: var(--font); font-size: 1rem; color: var(--ink); margin-bottom: 8px; }
.card-footer { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-top: 0.5px solid var(--ivory-border); }
.card-board  { height: 144px; background: var(--wood-light); border-bottom: 0.5px solid var(--ivory-border); display: flex; align-items: center; justify-content: center; overflow: hidden; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* ── Site footer ── */
.site-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 0.5px solid var(--ivory-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--ink-muted);
}
.site-footer a       { color: var(--ink-muted); text-decoration: none; }
.site-footer a:hover { color: var(--ink); }

/* ── Auth page ── */
.auth-page { max-width: 800px; margin: 3rem auto; }
.auth-grid { display: grid; gap: 24px; }
@media (min-width: 640px) {
  .auth-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Landing / hero ── */
.ds-hero {
  padding: 4rem 0 3rem;
  border-bottom: 0.5px solid var(--ivory-border);
  margin-bottom: 3rem;
}

.ds-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.ds-card-wide { grid-column: 1 / -1; }

/* ── Homepage demo board ── */
.demo-why-layout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2rem;
  align-items: center;
}

.demo-board-link {
  display: block;
  flex-shrink: 0;
  line-height: 0;
}

#demo-board {
  display: block;
  width: 288px;
  height: auto;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 0.5px solid var(--ivory-border);
}

/* Keep old landing-page structures for grid pages */
.landing-page { display: flex; flex-direction: column; gap: 1.5rem; width: 100%; }
.landing-top  { width: 100%; }
.landing-card-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
  align-items: stretch;
}
.landing-card-wide { grid-column: 1 / -1; }
.landing-card { width: 100%; margin-bottom: 0; }
.hero-lead, .section-lead { max-width: 42rem; color: var(--ink-mid); }
.row.main { row-gap: 1.5rem; }
.main.container { padding-top: 2rem; padding-bottom: 2rem; }

/* ── New game page ── */
.new-game-grid { display: grid; gap: 24px; }
@media (min-width: 768px) { .new-game-grid { grid-template-columns: 2fr 1fr; } }

/* ── Games list page ── */
.games-page-header { margin-bottom: 2rem; }
.game-list-card { text-decoration: none; color: inherit; display: block; }
.game-list-card:hover .card-title { color: var(--blood); }
.game-list-card-wrapper .game-delete-form { opacity: 0; transition: opacity 0.15s; }
.game-list-card-wrapper:hover .game-delete-form { opacity: 1; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 3rem 2rem; }
.empty-state .t-heading { margin-bottom: 0.75rem; }

/* ---------------------------------------------------------------------------
   Game page — board, panel, captures, chat
   --------------------------------------------------------------------------- */

.game {
  width: 100%;
  display: block;
  border: 0.5px solid var(--ivory-border);
  margin: 0;
  border-radius: 0;
  background: var(--wood-light);
}

.game-layout {
  display: grid !important;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin: 0;
  align-items: start;
}

@media (min-width: 768px) {
  .game-layout {
    grid-template-columns: 2fr 1fr;
  }
}

.game-board-column,
.game-panel-column { display: flex; }

/* Game columns override the col-lg padding since game-layout uses grid gap */
.game-layout .game-board-column,
.game-layout .game-panel-column {
  padding: 0;
  width: auto;
}

.board-stage { width: 100%; }

.board-stage-copy { margin-bottom: 1.5rem; }

.board-frame {
  box-sizing: border-box;
  padding: 1.5rem;
  border: 0.5px solid var(--ivory-border);
  border-radius: var(--radius-lg);
  background: var(--ivory-mid);
}

.game-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* .panel-card kept as alias for .card */
.panel-card {
  box-sizing: border-box;
  padding: 16px 18px;
  margin-bottom: 18px;
  border: 0.5px solid var(--ivory-border);
  border-radius: var(--radius-lg);
  background: var(--white);
}

.matchup-card { background: linear-gradient(180deg, var(--white) 0%, var(--ivory-mid) 100%); }

.matchup-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
  margin: 0;
  font-size: 1.1rem;
}

.matchup-separator { color: var(--ink-muted); }

.status-stack { margin-bottom: 0; }
.compact-stack .status-row:last-child { margin-bottom: 0; }

.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--ivory-mid);
}

.status-row input { margin: 0; }

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.action-row .btn { flex: 1 1 10rem; }

.capture-block + .capture-block { margin-top: 1rem; }

.capture-heading {
  margin: 0 0 8px;
  font-size: .875rem;
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
}

.capture-tray {
  min-height: 38px;
  padding: 10px 12px;
  border: 0.5px solid var(--ivory-border);
  border-radius: var(--radius-sm);
  background: var(--ivory-mid);
  color: var(--ink-mid);
  font-size: 0.9375rem;
  line-height: 1.55;
}

.capture-chip {
  margin: 0 8px 8px 0;
  padding: 6px 12px;
  border: 0.5px solid var(--ivory-border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: inherit;
  font-size: 0.9rem;
}

.capture-chip-selectable { cursor: pointer; }

.capture-chip-selected {
  background: var(--wood-light);
  border-color: var(--wood);
  color: var(--ink);
}

.panel-note p { color: var(--ink-mid); font-size: 13px; }

/* ── Chat ── */
.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-message-list {
  height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  border: 0.5px solid var(--ivory-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  background: var(--ivory-mid);
}

.chat-message { display: flex; gap: 0.5rem; font-size: 0.85rem; flex-wrap: wrap; }
.chat-name    { font-weight: 600; flex-shrink: 0; color: var(--ink); }
.chat-time    { color: var(--ink-muted); flex-shrink: 0; font-size: 0.75rem; align-self: center; }
.chat-text    { flex: 1; word-break: break-word; color: var(--ink-mid); }

.chat-input-row { display: flex; gap: 8px; align-items: center; }
.chat-input-row input  { flex: 1; min-width: 0; }
.chat-input-row button { flex-shrink: 0; }

/* ── Agent thinking panel ── */
.agent-thinking-panel { margin-top: 1.5rem; }

.agent-thinking-log {
  height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  border: 0.5px solid var(--ivory-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  background: var(--ivory-mid);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.agent-thought { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.agent-thought-kind {
  flex-shrink: 0;
  font-weight: 600;
  min-width: 6rem;
  color: var(--ink-muted);
}
.agent-thought-tool_call .agent-thought-kind { color: var(--wood-dark); }
.agent-thought-tool_result .agent-thought-kind { color: var(--ink-mid); }
.agent-thought-final .agent-thought-kind { color: var(--blood); font-weight: 700; }
.agent-thought-content { flex: 1; word-break: break-all; color: var(--ink-mid); }

/* ── Piece tooltip ── */
.piece-tooltip {
  position: fixed;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
}

/* ── Responsive ── */
@media (max-width: 767px) {
  body { font-size: 14px; }

  .page-content { padding: 2rem 1rem 4rem; }

  /* Hide desktop nav, show hamburger */
  .site-nav { display: none; }
  .nav-hamburger { display: flex; }

  /* Show mobile drawer when checkbox is checked */
  .nav-toggle-checkbox:checked ~ .site-nav-mobile {
    display: block;
  }

  .btn { width: 100%; margin-bottom: 8px; }
  .btn-grid { flex-direction: column; }

  .board-frame,
  .panel-card { padding: 14px; border-radius: var(--radius-md); }

  .board-stage-copy { margin-bottom: 1rem; }

  .matchup-line { font-size: 1rem; }

  .action-row .btn { flex-basis: 100%; }

  .form-row { grid-template-columns: 1fr; }

  .ds-card-grid { grid-template-columns: 1fr; }
  .landing-card-grid { grid-template-columns: 1fr; }

  .demo-why-layout { grid-template-columns: 1fr; }
  #demo-board { width: 100%; }

  .auth-grid { grid-template-columns: 1fr; }
  .new-game-grid { grid-template-columns: 1fr; }

  .chat-input-row { flex-direction: column; align-items: stretch; }
}

@media (min-width: 768px) {
  .game-panel-column {
    top: 68px;
  }
}
