:root {
  color-scheme: dark;
  --bg: #100d0b;
  --bg-deep: #070605;
  --panel: rgba(34, 28, 23, 0.95);
  --panel-soft: rgba(47, 39, 31, 0.9);
  --card-tint: rgba(167, 55, 49, 0.12);
  --card-tint-2: rgba(216, 181, 111, 0.1);
  --card-border: rgba(216, 181, 111, 0.24);
  --card-inner: rgba(216, 181, 111, 0.12);
  --parchment: #2a241d;
  --parchment-light: #403527;
  --text: #f5efe2;
  --muted: #c5b7a2;
  --line: rgba(211, 179, 123, 0.28);
  --line-strong: rgba(216, 177, 105, 0.5);
  --accent: #a73731;
  --accent-bright: #d8614f;
  --accent-2: #d8b56f;
  --danger: #e17063;
  --field: rgba(13, 11, 9, 0.86);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 12% 8%, rgba(168, 53, 46, 0.24), transparent 28rem),
    radial-gradient(circle at 86% 16%, rgba(216, 181, 111, 0.12), transparent 24rem),
    linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 13px),
    linear-gradient(180deg, var(--bg), var(--bg-deep));
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent, rgba(216, 181, 111, 0.05), transparent),
    radial-gradient(circle at 50% -10%, rgba(216, 181, 111, 0.07), transparent 36rem);
  opacity: 0.85;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(74, 57, 43, 0.94), rgba(36, 28, 23, 0.96));
  color: var(--text);
  cursor: pointer;
  padding: 9px 13px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, background 160ms ease;
}

button:hover,
button:focus-visible,
.file-button:hover,
.file-button:focus-visible {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(216, 181, 111, 0.12);
  outline: none;
  transform: translateY(-1px);
}

button:active,
.file-button:active {
  transform: translateY(0);
}

button.danger {
  border-color: rgba(225, 112, 99, 0.65);
  color: #ffe1dc;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(216, 181, 111, 0.22);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent),
    var(--field);
  color: var(--text);
  padding: 10px 11px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(216, 181, 111, 0.13);
  outline: none;
}

textarea {
  min-height: 112px;
  resize: vertical;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
}

.app-shell {
  position: relative;
  width: min(1540px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 28px 0 52px;
  animation: pageReveal 520ms ease both;
}

.topbar,
.panel,
.sheet-section {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 244, 213, 0.045), transparent 40%),
    linear-gradient(135deg, var(--card-tint), transparent 46%),
    linear-gradient(315deg, var(--card-tint-2), transparent 54%),
    var(--panel);
  box-shadow: var(--shadow);
}

.topbar::after,
.panel::after,
.sheet-section::after,
.display-card::after {
  content: "";
  position: absolute;
  inset: 7px;
  pointer-events: none;
  border: 1px solid var(--card-inner);
  border-radius: 5px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: center;
  padding: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent-2);
  text-transform: uppercase;
  font: 700 0.76rem ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.08em;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  color: #fff6e5;
  font-size: clamp(2.2rem, 4.4vw, 4.6rem);
  line-height: 0.95;
  text-shadow: 0 0 28px rgba(216, 181, 111, 0.15);
}

h2 {
  color: #fff3dc;
  font-size: 1.28rem;
}

h3 {
  color: #f5e3c0;
  font-size: 1.02rem;
}

.toolbar,
.section-title-row,
.row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar {
  justify-content: flex-end;
}

.theme-control {
  min-height: 40px;
  display: grid;
  grid-template-columns: auto minmax(170px, 1fr);
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font: 700 0.72rem ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.theme-control.compact {
  grid-template-columns: auto 42px;
}

.theme-control select {
  min-height: 40px;
  padding-block: 7px;
}

.theme-control input[type="color"] {
  width: 42px;
  min-width: 42px;
  height: 40px;
  padding: 4px;
  cursor: pointer;
}

#import-character {
  display: none;
}

.panel,
.sheet-section {
  padding: 20px;
  margin-bottom: 18px;
  animation: panelRise 460ms ease both;
}

.sheet-section {
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.sheet-section:hover,
.display-card:hover,
.list-row:hover {
  border-color: var(--line-strong);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

.section-title-row {
  justify-content: space-between;
  margin-bottom: 15px;
}

.note,
.status-line {
  color: var(--muted);
  margin: 6px 0 0;
}

.status-line {
  min-height: 28px;
  padding-left: 4px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.auth-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-actions {
  display: flex;
  align-items: end;
}

.cloud-panel {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.list {
  display: grid;
  gap: 10px;
}

.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid rgba(216, 181, 111, 0.2);
  border-radius: 7px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent), var(--panel-soft);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.list-meta {
  color: var(--muted);
  font: 0.82rem ui-sans-serif, system-ui, sans-serif;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  transition: opacity 180ms ease, transform 180ms ease;
}

.full {
  grid-column: 1 / -1;
}

.dot-table,
.health-grid,
.display-grid,
.display-stack,
.display-stat-grid,
.display-health-list {
  display: grid;
  gap: 11px;
}

.dot-row {
  display: grid;
  grid-template-columns: minmax(128px, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid rgba(216, 181, 111, 0.1);
}

.dot-row:last-child {
  border-bottom: 0;
}

.dot-label,
.named-stack {
  display: grid;
  gap: 7px;
}

.dot-label {
  color: var(--text);
}

.dot-label span {
  font-weight: 700;
}

.specialty-input {
  min-height: 32px;
  padding: 7px 9px;
  border-color: rgba(216, 181, 111, 0.16);
  color: var(--muted);
  font: 0.78rem ui-sans-serif, system-ui, sans-serif;
}

.specialty-input::placeholder {
  color: rgba(197, 183, 162, 0.55);
}

.dots {
  display: grid;
  grid-template-columns: 26px repeat(10, 20px);
  gap: 5px;
  align-items: center;
}

.dot,
.dot-count {
  width: 20px;
  height: 20px;
  min-height: 20px;
  border-radius: 50%;
  padding: 0;
  border-color: rgba(197, 183, 162, 0.72);
  background: rgba(0, 0, 0, 0.24);
}

.dot-count {
  display: inline-grid;
  place-items: center;
  width: 26px;
  border-radius: 999px;
  color: var(--muted);
  font: 700 0.68rem ui-sans-serif, system-ui, sans-serif;
}

.dot.filled {
  background: radial-gradient(circle at 35% 30%, #fff0c6, var(--accent-2) 48%, #9d6d2d);
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(216, 181, 111, 0.12), 0 0 12px rgba(216, 181, 111, 0.22);
  animation: dotKindle 220ms ease;
}

.named-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.health-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 72px auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid rgba(216, 181, 111, 0.12);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.14);
}

.health-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
}

.display-panel[hidden],
.sheet-grid[hidden] {
  display: none;
}

.display-panel {
  transition: opacity 180ms ease, transform 180ms ease;
}

.display-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

.display-card {
  position: relative;
  overflow: hidden;
  min-height: 100px;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255, 244, 213, 0.045), transparent),
    radial-gradient(circle at 18% 12%, var(--card-tint), transparent 14rem),
    linear-gradient(135deg, var(--card-tint-2), transparent 62%),
    var(--panel-soft);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
  transition: border-color 170ms ease, box-shadow 170ms ease, background 170ms ease;
}

.display-card.large {
  min-height: 180px;
}

.display-spec-row {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
}

.display-spec-row > h3 {
  margin: 2px 0 0;
  color: var(--accent-2);
  font: 700 0.82rem ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.display-spec-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 11px;
}

.display-card strong,
.display-card h3 {
  display: block;
  margin-bottom: 8px;
  color: var(--accent-2);
  font: 700 0.78rem ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.display-card span,
.display-card p {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
}

.display-hero {
  grid-column: 1 / -1;
  min-height: 170px;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.8fr);
  gap: 18px;
  align-items: end;
  background:
    radial-gradient(circle at 18% 16%, rgba(168, 53, 46, 0.2), transparent 18rem),
    linear-gradient(135deg, rgba(216, 181, 111, 0.09), transparent 48%),
    var(--panel);
}

.display-name {
  color: #fff6e5;
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 0.95;
}

.display-subtitle {
  margin-top: 12px;
  color: var(--muted);
  font-size: 1.05rem;
}

.display-kv {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.display-kv div,
.display-stat,
.display-health-item {
  border: 1px solid rgba(216, 181, 111, 0.14);
  border-radius: 6px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.16);
}

.display-kv b,
.display-stat b,
.display-health-item b {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font: 700 0.7rem ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.display-stat-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.display-stat span {
  color: var(--accent-2);
  font-size: 1.5rem;
}

.display-rating-list {
  display: grid;
  gap: 14px;
}

.display-rating-group {
  display: grid;
  gap: 7px;
}

.display-rating-group h4 {
  margin: 0;
  color: var(--muted);
  font: 700 0.72rem ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.display-rating-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 10px;
  align-items: center;
  border: 1px solid rgba(216, 181, 111, 0.12);
  border-radius: 6px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.14);
}

.display-rating-row b {
  color: var(--text);
  font-weight: 700;
}

.display-rating-row span {
  color: var(--accent-2);
  font: 700 1rem ui-sans-serif, system-ui, sans-serif;
}

.display-dot-wrap {
  display: grid;
  grid-template-columns: 22px auto;
  gap: 8px;
  align-items: center;
}

.display-rating-number {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  color: var(--accent-2);
  font: 800 0.92rem ui-sans-serif, system-ui, sans-serif;
}

.display-dots {
  display: grid;
  grid-template-columns: repeat(10, 8px);
  gap: 3px;
}

.display-dots i {
  width: 8px;
  height: 8px;
  border: 1px solid rgba(197, 183, 162, 0.58);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
}

.display-dots i.filled {
  border-color: var(--accent-2);
  background: var(--accent-2);
  box-shadow: 0 0 8px rgba(216, 181, 111, 0.22);
}

.display-rating-row small,
.display-stat small {
  grid-column: 1 / -1;
  color: var(--muted);
  font: 0.78rem ui-sans-serif, system-ui, sans-serif;
  line-height: 1.35;
}

.display-health-item.marked {
  border-color: rgba(225, 112, 99, 0.52);
  background: rgba(167, 55, 49, 0.17);
}

.mode-fade {
  animation: modeFade 240ms ease both;
}

@keyframes pageReveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes panelRise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dotKindle {
  from {
    transform: scale(0.78);
    opacity: 0.7;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes modeFade {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1220px) {
  .sheet-grid,
  .display-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .form-grid,
  .auth-grid,
  .sheet-grid,
  .display-grid,
  .display-hero {
    grid-template-columns: 1fr;
  }

  .display-hero {
    min-height: auto;
  }

  .display-spec-grid {
    grid-template-columns: 1fr;
  }

  .dot-row,
  .named-row,
  .health-row,
  .list-row {
    grid-template-columns: 1fr;
  }

  .dots {
    grid-template-columns: 26px repeat(10, minmax(14px, 1fr));
  }

  .dot,
  .dot-count {
    width: 100%;
    aspect-ratio: 1;
    height: auto;
  }

  .dot-count {
    aspect-ratio: auto;
    height: 24px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 18px, 1540px);
    padding-top: 12px;
  }

  .topbar,
  .panel,
  .sheet-section {
    padding: 15px;
  }

  .display-kv,
  .display-stat-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
