:root {
  color-scheme: light;
  --ink: #14110e;
  --paper: #f6f3ee;
  --panel: #ffffff;
  --line: #cfc8bd;
  --accent: #7a1f1f;
  --accent-strong: #561515;
  --focus: #1e6d8f;
  --shadow: 0 12px 28px rgba(28, 24, 20, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;

  background: #e8e2d8;
  color: var(--ink);

  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

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

button {
  min-height: 36px;
  padding: 0 12px;

  color: var(--ink);
  background: #fffaf2;

  border: 1px solid #b7ab9b;
  border-radius: 6px;

  cursor: pointer;
}

button:hover {
  background: #fff3e0;
}

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

button.primary {
  color: white;
  background: var(--accent);
  border-color: var(--accent-strong);
}

button.primary:hover {
  background: var(--accent-strong);
}

button.danger {
  color: #842222;
  border-color: #ba8a8a;
}

button.mode-toggle.active {
  color: #f7e8c2;
  background: #241716;
  border-color: #8a6b32;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

/* Main application layout */

.site-app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);

  min-height: 100vh;

  transition: grid-template-columns 180ms ease;
}

.site-app.sidebar-is-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.site-main {
  display: flex;
  flex-direction: column;

  min-width: 0;
  min-height: 100vh;
}

.sheet-app {
  display: flex;
  flex-direction: column;

  min-height: 100vh;
}

/* Sidebar */

.site-sidebar {
  position: sticky;
  top: 0;

  display: flex;
  flex-direction: column;
  align-self: start;

  width: 260px;
  height: 100vh;
  min-width: 0;
  min-height: 100vh;
  padding: 10px;

  overflow-y: auto;

  border-right: 1px solid #c9bdac;
  background: #f6f3ee;

  transition:
    width 180ms ease,
    min-width 180ms ease,
    opacity 180ms ease,
    padding 180ms ease;
}

.site-sidebar.collapsed {
  width: 0;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;

  overflow: hidden;
  opacity: 0;
  pointer-events: none;

  border-right: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;

  min-height: 48px;
  padding: 0 4px;

  color: #231914;
  background: transparent;
  border-color: transparent;

  font-size: 17px;
  font-weight: 860;
  text-align: left;
}

.sidebar-brand:hover {
  background: transparent;
}

.brand-mark {
  display: grid;
  place-items: center;

  width: 40px;
  height: 40px;

  color: #f7e8c2;
  background: #241716;

  border: 1px solid #8a6b32;
  border-radius: 8px;

  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  font-weight: 900;
}

.sidebar-nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;

  margin-top: 20px;
}

.sidebar-item,
.sidebar-subitem {
  display: flex;
  align-items: center;
  justify-content: space-between;

  width: 100%;
  min-height: 40px;
  padding: 0 12px;

  color: #33271f;
  background: transparent;
  border-color: transparent;

  text-align: left;
}

.sidebar-item {
  font-weight: 600;
}

.sidebar-subitem {
  min-height: 36px;

  font-size: 14px;
  font-weight: 400;
}

.sidebar-item:hover,
.sidebar-subitem:hover {
  background: #fff7e8;
}

.sidebar-item.active,
.sidebar-subitem.active {
  color: #fffaf2;
  background: #7a1f1f;
  border-color: #7a1f1f;
}

.sidebar-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.group-toggle {
  font-weight: 600;
}

.toggle-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  font-size: 20px;
  line-height: 1;

  transform: rotate(0deg);
  transition: transform 160ms ease;
}

.toggle-caret.open {
  transform: rotate(90deg);
}

.sidebar-subnav {
  display: flex;
  flex-direction: column;
  gap: 4px;

  padding-left: 12px;
}

/* Sidebar collapse controls */

.sidebar-collapse-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;

  width: 100%;
  min-height: 42px;
  margin-top: 14px;
  padding: 10px 12px;

  color: #000000;
  background: rgba(255, 255, 255, 0.025);

  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 8px;

  font: inherit;
  font-size: 0.84rem;

  cursor: pointer;

  transition:
    color 150ms ease,
    background 150ms ease,
    border-color 150ms ease;
}

.sidebar-collapse-button:hover {
  color: #000000;
  background: rgba(213, 168, 95, 0.1);
  border-color: rgba(0, 0, 0, 0.38);
}

.sidebar-collapse-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.sidebar-restore-button {
  position: fixed;
  bottom: 18px;
  left: 14px;
  z-index: 100;

  display: grid;
  place-items: center;

  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;

  color: #f1d39a;
  background: rgba(27, 18, 13, 0.9);

  border: 1px solid rgba(213, 168, 95, 0.42);
  border-radius: 50%;

  font-size: 1.8rem;
  line-height: 1;

  cursor: pointer;

  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.32);

  backdrop-filter: blur(8px);
}

.sidebar-restore-button:hover {
  color: #21160f;
  background: #e0b369;
}

.sidebar-restore-label {
  display: none;
}

.sidebar-restore-button:focus-visible,
.sidebar-collapse-button:focus-visible {
  outline: 3px solid rgba(241, 211, 154, 0.55);
  outline-offset: 3px;
}

/* Legacy home styles */

.home-page {
  display: grid;
  flex: 1;
  place-items: center;

  padding: 48px 24px;
}

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;

  width: min(860px, 100%);

  text-align: center;
}

.home-hero h1 {
  margin: 0 0 22px;

  color: #2a1810;

  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(48px, 8vw, 92px);
  line-height: 1.1;
}

.home-copy {
  width: min(720px, 100%);
  margin: 0;
  padding: 22px 24px;

  color: #3b2a1d;
  background: #fbf1df;

  border: 1px solid #a98d62;
  border-top: 5px solid #7a1f1f;
  border-radius: 8px;

  box-shadow: 0 4px 0 rgba(67, 45, 28, 0.12);

  font-size: 18px;
  font-weight: 560;
  line-height: 1.5;
}

/* Character sheet toolbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;

  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;

  padding: 10px 12px;

  background: rgba(246, 243, 238, 0.96);
  border-bottom: 1px solid var(--line);

  box-shadow: 0 2px 10px rgba(46, 37, 28, 0.08);

  backdrop-filter: blur(8px);
}

.header-peek {
  position: fixed;
  top: 8px;
  left: 272px;
  z-index: 35;

  min-height: 34px;

  background: rgba(255, 250, 242, 0.94);
  border-color: #7f6f5c;

  box-shadow: 0 4px 16px rgba(33, 25, 22, 0.18);
}

.brand {
  margin-right: 4px;

  font-weight: 760;
  letter-spacing: 0;
  white-space: nowrap;
}

.character-picker {
  display: flex;
  align-items: center;
  gap: 8px;

  min-width: 260px;
}

.character-picker label {
  color: #554b40;
  font-size: 14px;
}

.character-picker select,
.name-input {
  min-height: 36px;
  padding: 0 10px;

  color: var(--ink);
  background: #fffdf9;

  border: 1px solid #b7ab9b;
  border-radius: 6px;

  text-align: right;
}

.character-picker select {
  width: 190px;
}

.name-input {
  width: min(260px, 22vw);
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;

  margin-left: auto;
}

.status {
  min-width: 90px;

  color: #5b5248;
  font-size: 13px;
  text-align: right;
}

.error {
  width: min(1100px, calc(100% - 24px));
  margin: 12px auto 0;
  padding: 10px 12px;

  color: #7c241e;
  background: #fff6f4;

  border: 1px solid #c77b75;
  border-radius: 6px;
}

.loading {
  display: grid;
  place-items: center;

  min-height: 100vh;

  color: #4d4237;
}

/* Mobile layout */

@media (max-width: 860px) {
  .site-app,
  .site-app.sidebar-is-collapsed {
    display: flex;
    flex-direction: column;
  }

  .site-sidebar {
    position: sticky;
    top: 0;
    z-index: 40;

    display: grid;
    flex: 0 0 auto;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;

    width: 100%;
    height: auto;
    min-height: 0;
    padding: 10px;

    overflow: visible;

    border-right: 0;
    border-bottom: 1px solid #c9bdac;
  }

  .site-sidebar.collapsed {
    width: 0;
    height: 0;
    min-height: 0;
    padding: 0;

    overflow: hidden;
    opacity: 0;

    border-bottom: 0;
  }

  .sidebar-brand {
    width: 100%;
    flex-shrink: 0;
    min-width: 0;
  }

  .brand-mark {
    width: 34px;
    height: 34px;

    font-size: 12px;
  }

  .sidebar-nav {
    grid-column: 1 / -1;

    flex: 1;
    flex-direction: row;
    align-items: flex-start;

    width: 100%;
    min-width: 0;
    margin-top: 0;
    padding-bottom: 2px;

    overflow-x: auto;
    overflow-y: visible;
  }

  .sidebar-item {
    flex-shrink: 0;
    width: auto;
    min-width: max-content;
  }

  .sidebar-group {
    flex-direction: row;
    align-items: flex-start;
    flex-shrink: 0;
  }

  .sidebar-subnav {
    flex-direction: row;
    padding-left: 0;
  }

  .sidebar-subitem {
    min-width: max-content;
  }

  .sidebar-collapse-button {
    grid-column: 2;
    grid-row: 1;

    align-self: stretch;
    flex-shrink: 0;

    width: auto;
    min-width: 42px;
    margin-top: 0;
    padding: 8px;
  }

  .sidebar-collapse-label {
    display: inline;
  }

  .sidebar-restore-button {
    bottom: 12px;
    left: 12px;

    display: inline-flex;
    gap: 6px;
    align-items: center;
    width: auto;
    min-width: 84px;
    padding: 0 12px;
    border-radius: 999px;

    font-size: 1rem;
  }

  .sidebar-restore-label {
    display: inline;
    font-size: 0.84rem;
    font-weight: 850;
  }

  .home-page {
    min-height: calc(100vh - 92px);
    padding: 34px 14px;
  }

  .home-hero h1 {
    font-size: 46px;
  }

  .home-copy {
    padding: 18px;
    text-align: left;
  }

  .topbar {
    top: 0;

    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 8px;
    max-height: 64vh;
    overflow-y: auto;
  }

  .header-peek {
    position: sticky;
    top: 8px;
    left: auto;
    width: max-content;
    margin: 8px 0 0 8px;
  }

  .brand {
    width: 100%;
    white-space: normal;
  }

  .character-picker {
    flex: 1 1 100%;
    min-width: 0;
  }

  .character-picker select {
    flex: 1;
    width: auto;
  }

  .name-input {
    flex: 1 1 100%;
    width: 100%;
  }

  .actions {
    width: 100%;
    margin-left: 0;
    padding-bottom: 4px;

    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .actions button {
    flex: 0 0 auto;
  }

  .status {
    flex: 0 0 auto;
    margin-left: auto;
    min-width: max-content;
  }

  .sheet-app.header-hidden .sheet-scroll {
    padding-top: 12px;
  }
}

@media (max-width: 520px) {
  .site-sidebar {
    gap: 8px;
    padding: 8px;
  }

  .sidebar-brand {
    gap: 8px;
    min-height: 42px;
    font-size: 15px;
  }

  .sidebar-collapse-button {
    min-height: 38px;
    padding: 8px 10px;
  }

  .sidebar-collapse-label {
    display: none;
  }

  .topbar {
    padding: 8px;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
  }

  .actions button {
    width: 100%;
    min-width: 0;
  }

  .status {
    grid-column: 1 / -1;
    margin-left: 0;
    text-align: left;
  }
}
