/* 1. Use a more-intuitive box-sizing model */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 2. Remove default margin */
*:not(dialog) {
  margin: 0;
}

/* 3. Enable keyword animations */
@media (prefers-reduced-motion: no-preference) {
  html {
    interpolate-size: allow-keywords;
  }
}

body {
  /* 4. Add accessible line-height */
  line-height: 1.5;
  /* 5. Improve text rendering */
  -webkit-font-smoothing: antialiased;
}

/* 6. Improve media defaults */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

/* 7. Inherit fonts for form controls */
input,
button,
textarea,
select {
  font: inherit;
}

/* 8. Avoid text overflows */
p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

/* 9. Improve line wrapping */
p {
  text-wrap: pretty;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
}

/*
  10. Create a root stacking context
*/
#root,
#__next {
  isolation: isolate;
}

button {
  border: none;
}

button:hover {
  cursor: pointer;
}

ul {
  padding: 0;
}

li {
  list-style: none;
}

a,
a:visited {
  text-decoration: none;
}

/* Main Page Title (e.g., "Overview", "Settings") */

h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Card/Widget Titles */

h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

/* Section subsections / Key Data Metrics */

h3 {
  font-size: 1rem;
  font-weight: 600;
}

/* Column Headers (often Uppercase + Bold) */

h4 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05rem;
}

/* Standard data tables, logs, standard text */

p,
li,
input,
table {
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Meta text, timestamps, footnotes */

small,
caption {
  font-size: 0.75rem;
}

:root {
  /* Base neutrals (already have these) */
  --stone-50: #fafaf9;
  --stone-100: #f5f5f4;
  --stone-200: #e7e5e4;
  --stone-300: #d6d3d1;
  --stone-400: #a8a29e;
  --stone-500: #78716c;
  --stone-600: #57534e;
  --stone-700: #44403c;
  --stone-800: #292524;
  --stone-900: #1c1917;
  --stone-950: #0c0a09;

  /* Background / surfaces (light theme) */
  --bg-body: var(--stone-100);
  --bg-surface: var(--stone-50); /* cards, panels */
  --bg-subtle: var(--stone-200); /* subtle section backgrounds */

  /* Borders */
  --border-subtle: var(--stone-200);
  --border-strong: var(--stone-300);

  /* Text */
  --text-primary: var(--stone-900);
  --text-secondary: var(--stone-600);
  --text-muted: var(--stone-500);

  --text-link: var(--text-primary);

  /* Interactive (outline / focus / active) */
  --outline: var(--stone-400); /* focus rings */
  --button-bg: var(--stone-900); /* primary button */
  --button-bg-hover: var(--stone-800);
  --button-text: var(--stone-50);
  --button-border: var(--stone-800);
  --radius-sm: 0.25rem;
  --sidebar-active-bg: var(--stone-900);
  --sidebar-active-text: var(--stone-50);

  /* Subtle button / chips */
  --chip-bg: var(--stone-200);
  --chip-text: var(--stone-800);
}

[data-theme="dark"] {
  --bg-body: #090909;
  --bg-surface: #101010;
  --bg-subtle: var(--stone-800);

  --border-subtle: var(--stone-800);
  --border-strong: var(--stone-700);

  --text-primary: var(--stone-50);
  --text-secondary: var(--stone-300);
  --text-muted: var(--stone-400);

  --text-link: var(--text-primary);

  --outline: var(--stone-500);
  --button-bg: var(--stone-50);
  --button-bg-hover: var(--stone-200);
  --button-text: var(--stone-900);
  --button-border: var(--stone-200);
  --radius-sm: 0.25rem;
  --sidebar-active-bg: var(--stone-800);
  --sidebar-active-text: var(--stone-50);

  --chip-bg: var(--stone-800);
  --chip-text: var(--stone-50);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg-body: #090909;
    --bg-surface: #101010;
    --bg-subtle: var(--stone-800);

    --border-subtle: var(--stone-800);
    --border-strong: var(--stone-700);

    --text-primary: var(--stone-50);
    --text-secondary: var(--stone-300);
    --text-muted: var(--stone-400);

    --outline: var(--stone-500);
    --button-bg: var(--stone-50);
    --button-bg-hover: var(--stone-200);
    --button-text: var(--stone-900);
    --button-border: var(--stone-200);
    --radius-sm: 0.25rem;
    --sidebar-active-bg: var(--stone-800);
    --sidebar-active-text: var(--stone-50);

    --chip-bg: var(--stone-800);
    --chip-text: var(--stone-50);
  }
}

[data-theme="dark"] .sidebar img:not([src*="logo_light.png"]),
[data-theme="dark"] .header img,
[data-theme="dark"] .project-actions img,
[data-theme="dark"] .trending img {
  filter: invert(1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .sidebar img:not([src*="logo_light.png"]),
  :root:not([data-theme]) .header img,
  :root:not([data-theme]) .project-actions img,
  :root:not([data-theme]) .trending img {
    filter: invert(1);
  }
}

[data-theme="light"] img[src*="logo_light.png"] {
  filter: invert(1);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) img[src*="logo_light.png"] {
    filter: invert(1);
  }
}

hr {
  border: 0;
  border-top: 1px solid var(--border-subtle);
}

html {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

body {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

/* COLORS */

span {
  color: var(--text-link);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  background-color: var(--button-bg);
  color: var(--button-text);
  border: 1px solid var(--button-border);
  border-radius: var(--radius-sm, 0.25rem);
  transition:
    background-color 120ms ease,
    color 120ms ease;
}

.btn-primary:hover {
  background-color: var(--button-bg-hover);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-primary:focus,
.btn-ghost:focus {
  outline: 2px solid var(--outline);
}

.text-primary {
  color: var(--text-primary);
}

input {
  padding: 0.5rem;
  border: 1px solid var(--input-border);
  border-radius: 0.25rem;
  background-color: transparent;
  color: inherit;
}

:root[data-theme="dark"] input {
  border: 1px solid #333;
}

input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-primary) inset !important;
  -webkit-text-fill-color: white !important;
}

/* LEVEL DESIGN */

.scene {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.walls {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 5rem 1fr 5rem;
  align-items: stretch;
  background: linear-gradient(180deg, #7a6a55 0%, #6a5948 70%, #5b4a3b 100%);
}

.wainscot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 24%;
  background: linear-gradient(180deg, #5b4636 0%, #4a3729 100%);
  box-shadow: inset 0 0.5rem 0 rgba(0, 0, 0, 0.15);
}

.light {
  background: radial-gradient(
    closest-side,
    rgba(255, 220, 150, 0.35),
    transparent
  );
}

.shelves {
  position: relative;
  display: grid;
  align-content: end;
  justify-items: center;
  padding-top: 2rem;
}

.floor {
  height: 28vh;
  background: linear-gradient(180deg, #3c2f28 0%, #2b211c 100%);
  position: relative;
}

.carpet {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 12%;
  bottom: 12%;
  background: linear-gradient(180deg, #7b1e1e 0%, #5b1414 100%);
  box-shadow: inset 0 0 1.375rem rgba(0, 0, 0, 0.45);
  border-radius: 0.375rem;
}

/* Shelf cubby */
.shelf-row {
  position: relative;
  display: block;
  background: #5a4636;
  box-shadow: 0 0.625rem 1.125rem rgba(0, 0, 0, 0.35);
  border-radius: 0;
  overflow: visible;
}

.shelf-back {
  position: absolute;
  inset: 12px 10px 14px 10px;
  background: linear-gradient(180deg, #564335 0%, #4b392c 100%);
  box-shadow: inset 0 0 0.625rem rgba(0, 0, 0, 0.35);
}

.shelf-ceiling {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 12px;
  background: linear-gradient(180deg, #4b3729 0%, #3c2b20 100%);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.35);
  z-index: 2;
}

.shelf-floor {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 14px;
  background: linear-gradient(180deg, #6b4e3a 0%, #533b2b 100%);
  box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.shelf-left,
.shelf-right {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12px;
  background: #3c2b20;
  box-shadow: inset -2px 0 4px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.shelf-left {
  left: 0;
}

.shelf-right {
  right: 0;
  box-shadow: inset 2px 0 4px rgba(0, 0, 0, 0.4);
}

.shelf-books {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  bottom: 14px;
  display: flex;
  align-items: flex-end;
  gap: 0.375rem;
  z-index: 3;
  overflow: visible;
}

/* book */
.book {
  position: relative;
}

.book::after {
  content: attr(data-title);
  position: absolute;
  left: 50%;
  bottom: 100%;
  z-index: 4;
  transform: translate(-50%, -6px);
  white-space: nowrap;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 0.25rem;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 120ms ease,
    transform 120ms ease;
  color: #fff;
  background: #444;
}

.book:hover::after {
  opacity: 1;
  transform: translate(-50%, -10px);
}

.book[data-read="true"]:hover::after {
  background: #16a34a;
}

.book[data-read="false"]:hover::after {
  background: #dc2626;
}

/* add book */

.shelf-row .add-book {
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.shelves:hover .add-book {
  opacity: 1;
  pointer-events: auto;
}

.add-book {
  appearance: none;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 0;
  outline: none;
  position: relative;
  box-shadow:
    0 0 12px rgba(255, 255, 255, 0.35),
    inset 0 0 12px rgba(255, 255, 255, 0.25);
  transition:
    box-shadow 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease;
}

.add-book:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.95);
  box-shadow:
    0 0 18px rgba(255, 255, 255, 0.6),
    inset 0 0 16px rgba(255, 255, 255, 0.35);
}

.add-book::after {
  content: attr(aria-label);
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, -6px);
  white-space: nowrap;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 0.25rem;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 120ms ease,
    transform 120ms ease;
  color: #fff;
  background: #444;
}

.add-book:hover::after {
  opacity: 1;
  transform: translate(-50%, -10px);
}

@keyframes book-glow {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 1;
  }
}

.add-book-dialog::backdrop {
  background: rgba(20, 16, 12, 0.6);
  backdrop-filter: blur(2px);
}

.add-book-dialog {
  border: none;
  padding: 0;
  background: transparent;
}

.add-book-form {
  width: min(420px, 90vw);
  background: #f7f3ee;
  color: #2a1f18;
  border: 1px solid #d8cfc4;
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  display: grid;
  gap: 12px;
  position: relative;
}

.add-book-form .close-dialog {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: none;
  background: #f7f3ee;
  display: grid;
  place-items: center;
  padding: 0;
}

.add-book-form .close-dialog img {
  width: 18px;
  height: 18px;
}

.add-book-form h3 {
  margin-bottom: 6px;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.add-book-form label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: #3a2c22;
}

.add-book-form .checkbox-field {
  display: flex;
  align-items: center;
  justify-content: start;
  gap: 12px;
}

.add-book-form .checkbox-field input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
}

.add-book-form input[type="text"],
.add-book-form input[type="number"],
.add-book-form input[type="checkbox"],
.add-book-form input {
  padding: 8px 10px;
  border: 1px solid #d1c6b9;
  border-radius: 8px;
  background: #fffdf9;
  color: inherit;
}

.add-book-form input:focus {
  outline: 2px solid rgba(122, 90, 62, 0.5);
  border-color: #bfae9a;
}

.add-book-form input:-webkit-autofill,
.add-book-form input:-webkit-autofill:hover,
.add-book-form input:-webkit-autofill:focus,
.add-book-form input:-webkit-autofill:active {
  -webkit-text-fill-color: #2a1f18 !important;
  box-shadow: inset 0 0 20px 20px #fffdf9 !important;
  border: 1px solid #d1c6b9;
  transition: background-color 5000s ease-in-out 0s;
}

.add-book-form menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.add-book-form button {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #bcae9f;
  background: #eee6dd;
}

.add-book-form button[type="submit"] {
  background: #5a4636;
  color: #f7f3ee;
  border-color: #5a4636;
}

.add-book-form .delete-book.danger {
  background: #b91c1c;
  color: #fff;
  border-color: #b91c1c;
}

/* confirm delete dialog */
.confirm-delete-dialog::backdrop {
  background: rgba(20, 16, 12, 0.6);
  backdrop-filter: blur(2px);
}

.confirm-delete-dialog {
  border: none;
  padding: 0;
  background: transparent;
}

.confirm-delete-form {
  width: min(360px, 88vw);
  background: #f7f3ee;
  color: #2a1f18;
  border: 1px solid #d8cfc4;
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  display: grid;
  gap: 10px;
}

.confirm-delete-form menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-delete-form .confirm-yes {
  background: #b91c1c;
  color: #fff;
  border: 1px solid #b91c1c;
  border-radius: 8px;
  padding: 8px 12px;
}

.confirm-delete-form .confirm-no {
  background: #eee6dd;
  border: 1px solid #bcae9f;
  border-radius: 8px;
  padding: 8px 12px;
}

/* edit book */

.book .edit-book {
  position: absolute;
  inset: -0.25rem;
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.45);
  opacity: 0;
  pointer-events: none;
  background: transparent;
}

.book:hover .edit-book {
  opacity: 1;
  pointer-events: auto;
}

/* LAYOUT */

body {
  min-height: 100vh;
}
