:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --fg: #1c1c1a;
  --muted: #6b6b66;
  --accent: #166b45;
  --border: #e2e2dd;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --surface: #1d1d1b;
    --fg: #ececea;
    --muted: #9a9a94;
    --accent: #5fbf8a;
    --border: #2e2e2b;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: min(960px, 92vw);
  margin: 0 auto;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 0;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.lang-switch,
.site-nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.lang-switch a,
.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
}

.lang-switch a:hover,
.site-nav a:hover {
  color: var(--fg);
  background: color-mix(in srgb, var(--fg) 6%, transparent);
}

.lang-switch a.active {
  color: var(--accent);
  font-weight: 600;
}

main.container {
  flex: 1;
  padding: 3rem 0;
}

.hero {
  max-width: 38rem;
}

.hero h1 {
  font-size: clamp(2rem, 6vw, 3rem);
  margin: 0 0 0.75rem;
  letter-spacing: -0.02em;
}

.tagline {
  font-size: clamp(1.05rem, 2.6vw, 1.25rem);
  color: var(--muted);
  margin: 0;
}

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  padding: 1.25rem 0;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  main.container {
    padding: 2rem 0;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.panel.narrow {
  max-width: 26rem;
}

.panel h1 {
  margin-top: 0;
  font-size: 1.4rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head h1 {
  margin: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

textarea {
  resize: vertical;
}

input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

button.danger {
  background: #b3261e;
}

.notice {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--fg) 5%, transparent);
  border: 1px solid var(--border);
}

.notice.error {
  border-color: #b3261e;
  color: #b3261e;
}

.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
  background: var(--bg);
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px dashed var(--accent);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
}

.muted {
  color: var(--muted);
}

.prose h1 {
  margin-top: 0;
}

.prose h2 {
  font-size: 1.15rem;
  margin: 1.8rem 0 0.6rem;
}

.prose p {
  margin: 0 0 0.9rem;
}

.prose ul {
  margin: 0 0 0.9rem;
  padding-left: 1.3rem;
}

.prose li {
  margin-bottom: 0.35rem;
}

.prose pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
}

.prose pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.prose a {
  color: var(--accent);
  text-decoration: none;
}

.prose a:hover {
  text-decoration: underline;
}

.prose .badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.prose .badge:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.inline-form {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1rem 0 1.5rem;
}

.inline-form label {
  flex: 1 1 12rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1rem;
  margin-top: 2.5rem;
}

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--fg);
  text-decoration: none;
}

.card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.card:hover {
  border-color: var(--accent);
}

.options-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  color: var(--fg);
}

.render-result {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-start;
}

.render-result img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.result-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.preview {
  margin-top: 1.5rem;
}

.preview img {
  max-width: 100%;
  max-height: 24rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.squares {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 2px;
  max-width: 34rem;
  margin-top: 0.5rem;
}

.square {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.square .piece {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.square .square-name {
  font-size: 0.55rem;
  color: var(--muted);
}

.square .confidence {
  display: none;
  font-size: 0.55rem;
  color: var(--muted);
}

/* The checkbox must stay a sibling of .squares for this toggle to apply. */
#show-confidence {
  margin-right: 0.4rem;
}

#show-confidence:checked ~ .squares .confidence {
  display: block;
}

@media (max-width: 640px) {
  .squares {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .square .piece {
    font-size: 0.85rem;
  }

  .square .square-name {
    font-size: 0.5rem;
  }
}
