:root,
[data-theme="light"] {
  --bg: #d8d5ce;
  --bg-card: #e8e6df;
  --bg-muted: #ccc9c1;
  --text: #161615;
  --text-secondary: #3a3936;
  --text-muted: #6a6862;
  --border: #9e9a90;
  --accent: #8d5a2b;
  --red: #8c2f2f;
  --radius: 2px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #121211;
  --bg-card: #1c1c1a;
  --bg-muted: #2a2a26;
  --text: #e8e6df;
  --text-secondary: #b8b5ac;
  --text-muted: #7a776f;
  --border: #3f3e39;
  --accent: #8d5a2b;
  --red: #c45c4a;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #121211;
    --bg-card: #1c1c1a;
    --bg-muted: #2a2a26;
    --text: #e8e6df;
    --text-secondary: #b8b5ac;
    --text-muted: #7a776f;
    --border: #3f3e39;
    --accent: #8d5a2b;
    --red: #c45c4a;
    color-scheme: dark;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
}

body {
  font-family: var(--font);
  color: var(--text);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

::selection {
  background: var(--accent);
  color: #f0eee8;
}

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

header {
  flex: 0 0 auto;
}

.nav-bar {
  width: 100%;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand {
  color: var(--text) !important;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-decoration: none !important;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.nav-brand::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--accent);
}

.theme-toggle-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}
.theme-toggle-btn:hover {
  background: var(--bg-muted);
  color: var(--text);
}
.theme-toggle-btn svg {
  width: 16px;
  height: 16px;
}
html[data-theme="light"] .theme-toggle-btn .sun-icon { display: none; }
html[data-theme="light"] .theme-toggle-btn .moon-icon { display: block; }
html[data-theme="dark"] .theme-toggle-btn .sun-icon { display: block; }
html[data-theme="dark"] .theme-toggle-btn .moon-icon { display: none; }

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] .theme-toggle-btn .sun-icon { display: block; }
  html[data-theme="auto"] .theme-toggle-btn .moon-icon { display: none; }
}
@media (prefers-color-scheme: light) {
  html[data-theme="auto"] .theme-toggle-btn .sun-icon { display: none; }
  html[data-theme="auto"] .theme-toggle-btn .moon-icon { display: block; }
}

#main-content {
  flex: 1;
  min-height: 0;
  width: 100%;
  margin: 0;
  padding: 8px;
  display: flex;
}

#main-content.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 8px;
}

.card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.board .card[data-slot]::after {
  content: attr(data-slot);
  position: absolute;
  top: 6px;
  right: 8px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-muted);
  pointer-events: none;
  letter-spacing: 0.08em;
}

#main-content:not(.board) .card {
  flex: 1;
  width: 100%;
}

textarea,
pre.content {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  font: 0.875rem/1.5 var(--font-mono);
  resize: none;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
}
.board textarea {
  padding-right: 1.5rem;
}
textarea::placeholder {
  color: var(--text-muted);
}
textarea:focus-visible {
  outline-offset: -2px;
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 6px;
  margin-top: 0;
  padding: 8px;
  flex: 0 0 auto;
}
.board .actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.board .btn {
  width: 100%;
  min-width: 0;
  padding: 8px 4px;
  letter-spacing: 0.02em;
}

.btn {
  appearance: none;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-height: 36px;
  cursor: pointer;
  font: 500 0.8125rem/1 var(--font);
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover {
  background: var(--bg-muted);
}
.btn:active {
  background: var(--bg-muted);
}
.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #f0eee8;
}
.btn-primary:hover,
.btn-primary:active {
  background: var(--accent);
  filter: brightness(0.92);
}

.error {
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  padding: 12px;
}

.toast {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 400;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  #main-content.board {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(3, 1fr);
  }
}

@media (max-width: 560px) {
  html, body {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }
  #main-content.board {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .board .card {
    height: 42vh;
    min-height: 220px;
  }
  .board .btn {
    font-size: 0.75rem;
    padding: 8px 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
