:root {
  color-scheme: light dark;
  --bg: #f7f6f2;
  --text: #171713;
  --muted: #68675e;
  --line: #d9d7cc;
  --surface: #fffefa;
  --accent: #266f55;
  --accent-strong: #1d5d47;
  --danger: #9d3328;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151613;
    --text: #f4f1e8;
    --muted: #aaa69b;
    --line: #34352f;
    --surface: #1f211d;
    --accent: #63b992;
    --accent-strong: #78c9a4;
    --danger: #e07668;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
}

body.cartflix-empty {
  overflow-y: hidden;
}

body.sheet-open {
  overflow: hidden;
}

body.auth-pending .actions,
body.auth-pending .archive-list-action,
body.auth-pending .sheet {
  display: none !important;
}

.install-notice {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 30;
  width: min(420px, calc(100% - 20px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr 40px;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.14);
}

.install-notice p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.install-notice strong {
  display: block;
  color: var(--text);
  font-size: 15px;
}

.install-notice .icon-button {
  width: 40px;
  min-height: 40px;
  font-size: 22px;
  box-shadow: none;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  min-height: 44px;
  padding: 0 14px;
}

button:disabled {
  opacity: 0.58;
}

.startup-screen,
.auth-screen,
.welcome-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 18px 14px;
}

.startup-panel,
.auth-panel,
.welcome-panel {
  width: min(360px, 100%);
  display: grid;
  gap: 10px;
  text-align: center;
}

.startup-panel h1,
.auth-panel h1,
.welcome-panel h1 {
  margin-bottom: 0;
}

.motto {
  margin: -2px 0 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

#welcome-name {
  margin: 0 0 6px;
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
}

.auth-error {
  margin: 0;
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
}

.shell {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 18px 14px 128px;
}

body.cartflix-empty .shell {
  min-height: 100dvh;
  padding-bottom: 82px;
}

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

h1 {
  font-size: 28px;
  line-height: 1.1;
  margin: 0 0 4px;
  letter-spacing: 0;
}

#status {
  margin: 0;
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

.add-form {
  display: grid;
  grid-template-columns: 1fr minmax(72px, 108px) minmax(96px, 128px) 72px;
  gap: 8px;
  margin-bottom: 8px;
}

.history-hint {
  margin: 0 0 18px;
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

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

.category {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.category:has(.items:empty) {
  display: none;
}

h2 {
  margin: 0 0 10px;
  font-size: 15px;
  line-height: 1.2;
  color: var(--muted);
  letter-spacing: 0;
}

.items {
  display: grid;
  gap: 4px;
}

.item {
  display: grid;
  grid-template-columns: 1fr minmax(74px, 96px) 40px 40px;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.item-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.item-copy strong {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item-copy small {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.item.is-bought .item-copy strong {
  color: var(--muted);
  text-decoration: line-through;
}

.bought {
  min-height: 40px;
  padding: 0 10px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.item.is-bought .bought {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.edit,
.remove {
  width: 40px;
  min-height: 40px;
  padding: 0;
  background: transparent;
  border-color: transparent;
  font-size: 22px;
}

.edit {
  color: var(--accent-strong);
}

.remove {
  color: var(--danger);
  font-size: 24px;
}

.actions {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(720px, calc(100% - 20px));
  z-index: 10;
  display: grid;
  gap: 8px;
  margin: 0;
}

.settings-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  width: min(240px, 100%);
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16);
}

.settings-menu-button {
  width: 100%;
  justify-content: start;
  text-align: left;
}

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

.talk-button {
  flex: 1;
}

.archive-list-action {
  width: 100%;
  margin-top: 12px;
  box-shadow: var(--shadow);
}

.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
}

.sheet[aria-hidden="true"] {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.38);
}

.sheet-panel {
  position: relative;
  width: min(720px, 100%);
  max-height: min(78vh, 680px);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.18);
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--line);
}

.sheet-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
}

.chat-log {
  min-height: 220px;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 12px;
}

.chat-message {
  max-width: 86%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-message.user {
  justify-self: end;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chat-message.carty {
  justify-self: start;
}

.console-log {
  grid-template-columns: 1fr;
  min-height: 320px;
  padding-bottom: 16px;
}

.console-entry {
  display: grid;
  gap: 3px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.console-entry:last-child {
  border-bottom: 0;
}

.console-entry small {
  color: var(--muted);
  font-size: 12px;
}

.console-entry span {
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.console-entry.error span {
  color: var(--danger);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.password-panel {
  max-height: min(88dvh, 560px);
}

.password-form {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.password-message {
  margin: 0;
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
}

.password-message.is-error {
  color: var(--danger);
}

.empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 480px) {
  .shell {
    padding: 14px 10px 128px;
  }

  body.cartflix-empty .shell {
    padding-bottom: 78px;
  }

  .add-form {
    grid-template-columns: 1fr 82px;
  }

  .add-form select {
    grid-column: 1 / -1;
  }

  .add-form button {
    grid-column: 1 / -1;
  }

  .item {
    grid-template-columns: 1fr 74px 38px 38px;
  }

  .settings-menu {
    width: min(230px, calc(100vw - 20px));
  }
}
