:root {
  --paper: #ffffff;
  --ink: #111111;
  --muted: #6b6b6b;
  --line: #e0e0e0;
  --accent: #555555;
  --error: #bd3b3b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

.page {
  width: min(860px, calc(100% - 32px));
  margin: 32px auto;
}

.page.wide {
  width: min(1120px, calc(100% - 32px));
}

.analysis-form-page {
  margin-top: 64px;
}

.analysis-form-page .form-header,
.analysis-form-page .analyses-link,
.analysis-form-page .analysis-form-card,
.analysis-form-page .error {
  max-width: 720px;
}

.form-header {
  margin-bottom: 12px;
}

.analyses-link {
  display: block;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}

.analyses-link:hover {
  color: var(--ink);
}

.form-header h1 {
  font-size: 32px;
  margin-bottom: 6px;
}

.form-subtitle {
  color: var(--muted);
  margin: 0 0 14px;
  font-size: 15px;
}

.form-meta {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-meta li {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.meta-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--line);
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.meta-ok {
  background: #e6f4ea;
  color: #2a7a2a;
}

.meta-warn {
  background: #fff3cd;
  color: #7a5a00;
}

.analysis-form-card {
  background: #f8f8f8;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.pgn-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.pgn-field textarea {
  min-height: 280px;
  border-radius: 8px;
  border-color: var(--line);
  font-size: 13px;
  line-height: 1.6;
}

.pgn-field textarea:focus {
  outline: 2px solid #4a7fcb;
  outline-offset: -1px;
  border-color: transparent;
}

.form-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.btn-analyze {
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 28px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 0.15s;
  width: auto;
}

.btn-analyze:hover {
  background: #333;
}

h1,
h2,
h3 {
  margin: 0 0 16px;
  font-weight: 700;
  letter-spacing: 0;
}

h3 {
  margin-top: 18px;
  font-size: 16px;
}

label {
  display: block;
  margin: 0 0 8px;
  font-weight: 650;
}

.analysis-form {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

textarea,
pre {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8f8;
  color: var(--ink);
  font:
    14px/1.45 ui-monospace,
    SFMono-Regular,
    Menlo,
    Consolas,
    monospace;
}

textarea {
  min-height: 360px;
  padding: 14px;
  resize: vertical;
}

pre {
  overflow: auto;
  padding: 16px;
}

.collapsible {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8f8;
}

.collapsible summary {
  cursor: pointer;
  padding: 12px 14px;
  color: var(--ink);
  font-weight: 700;
}

.copy-button {
  margin: 0 14px 12px;
  padding: 6px 12px;
  font-size: 13px;
}

.collapsible pre,
.collapsible textarea {
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0 0 8px 8px;
  margin: 0;
  background: #ffffff;
}

button,
a {
  color: var(--ink);
}

button {
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}

.metadata {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px 16px;
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8f8;
}

.metadata div {
  min-width: 0;
}

.metadata dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metadata dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.config-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0 14px 14px;
}

.config-list div {
  display: grid;
  gap: 3px;
}

.config-list dt {
  font-weight: 700;
}

.config-list dd {
  margin: 0;
  color: var(--muted);
}

.markdown-analysis {
  max-height: 560px;
  line-height: 1.35;
  letter-spacing: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.copy-text {
  min-height: 260px;
}

.analysis-board {
  display: inline-block;
  aspect-ratio: 1 / 1;
  line-height: 1;
  letter-spacing: 0;
  white-space: pre;
  overflow-wrap: normal;
}

.summary {
  margin: 0 0 18px;
  color: var(--muted);
}

.error {
  border-left: 4px solid var(--error);
  margin: 0 0 16px;
  padding: 10px 12px;
  background: #fff0ee;
}

.progress-shell {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8f8;
  padding: 18px;
}

.progress-bar {
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #e8e8e8;
}

.progress-bar span {
  display: block;
  width: 6%;
  height: 100%;
  background: var(--ink);
  transition: width 160ms ease;
}

#analysis-progress-message {
  margin: 14px 0 10px;
  font-weight: 650;
}

#analysis-progress-log {
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
}

.analysis-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 22px;
  background: #f8f8f8;
}

.analysis-table th,
.analysis-table td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.analysis-table th {
  color: var(--muted);
  font-weight: 650;
}

.board-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.board-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8f8;
  padding: 12px;
}

.board-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.board-card pre {
  margin: 0;
  white-space: pre;
  font-size: 13px;
  letter-spacing: 0.15em;
  line-height: 1.75;
}

.widget-preview-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #ffffff;
}

.widget-preview-wrap chess-widget {
  --cw-widget-border-width: 0;
  --cw-paper: #ffffff;
  --cw-paper-deep: #f0f0f0;
  --cw-paper: #ffffff;
  --cw-paper-deep: #f0f0f0;
  --cw-ink: #111111;
  --cw-muted: #6b6b6b;
  --cw-line: #e0e0e0;
}

.wrap-pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.widget-customizer {
  margin: 24px 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--background-alt, #f9f9f9);
}

.widget-customizer h2 {
  margin: 0 0 14px;
}

.widget-customizer form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

.widget-customizer fieldset {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
}

.widget-customizer legend {
  font-size: 13px;
  color: var(--muted);
  font-weight: 650;
  padding: 0 4px;
}

.widget-customizer label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  cursor: pointer;
}

.panel-toggle-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.panel-name {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.panel-state-select {
  font-size: 13px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}

.analyzer-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
}

.analyzer-version,
.analyzer-elapsed {
  font-size: 12px;
  color: var(--muted);
}

.annotation-badge {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.annotation-blunder { background: #fde8e8; color: #c00; }
.annotation-mistake { background: #fff3cd; color: #7a5a00; }
.annotation-brilliant { background: #e8f5e9; color: #2a7a2a; }
.annotation-checkmate { background: #333; color: #fff; }

@media (max-width: 760px) {
  .analysis-form {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  button {
    width: max-content;
  }

  .widget-customizer form {
    flex-direction: column;
  }
}
