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

html, body {
  height: 100%;
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body {
  overflow: hidden;
}

#app {
  height: 100%;
}

/* ── Layout ── */

.app-layout {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 430px;
  margin: 0 auto;
}

/* ── Header ── */

.app-header {
  background: var(--primary);
  border-bottom-left-radius: 28px;
  border-bottom-right-radius: 28px;
  padding: 16px 20px 20px;
  flex-shrink: 0;
}

.header-row1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  min-height: 44px;
}

.wordmark {
  font-family: 'Bricolage Grotesque', Georgia, serif;
  font-size: 22px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1;
}

.wordmark-dot {
  color: var(--blush);
}

.header-row2 {
  display: flex;
  align-items: center;
  gap: 10px;
}

.screen-title {
  font-family: 'Bricolage Grotesque', Georgia, serif;
  font-size: 44px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1;
}

/* ── Main scroll area ── */

.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

/* ── Tab bar ── */

.tab-bar {
  display: flex;
  background: var(--surface);
  border-top: 1.5px solid var(--accent);
  padding-bottom: env(safe-area-inset-bottom);
  flex-shrink: 0;
  height: calc(84px + env(safe-area-inset-bottom));
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink);
  padding: 12px 0;
  min-height: 44px;
  min-width: 44px;
}

.tab-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}

.tab--active .tab-icon {
  color: var(--primary);
}

.tab-label {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}

.tab--active .tab-label {
  font-weight: 700;
}

/* ── Screens ── */

.screen {
  min-height: 100%;
}

.empty-state {
  text-align: center;
  color: var(--ink);
  opacity: 0.45;
  font-size: 15px;
  margin-top: 64px;
  line-height: 1.5;
}

/* ── Sign-in screen ── */

.sign-in-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 430px;
  margin: 0 auto;
}

.sign-in-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 24px;
}

.sign-in-prompt {
  font-size: 16px;
  text-align: center;
  color: var(--ink);
  opacity: 0.7;
}

.sign-in-error {
  font-size: 14px;
  text-align: center;
  color: #c0392b;
  background: #fde;
  padding: 10px 16px;
  border-radius: 12px;
  width: 100%;
  max-width: 320px;
}

/* ── Buttons ── */

.btn-primary {
  width: 100%;
  max-width: 320px;
  height: 56px;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: 18px;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ── Loading ── */

.loading-screen {
  height: 100%;
  background: var(--bg);
}

/* ── Floating add button ── */

.add-btn {
  position: fixed;
  right: 20px;
  bottom: calc(84px + env(safe-area-inset-bottom) + 16px);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  border: none;
  font-size: 30px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(99, 103, 255, 0.45);
  z-index: 10;
}

/* ── Sub-screen header back button ── */

.header-back {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen-title--sm {
  font-size: 32px;
}

.add-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 430px;
  margin: 0 auto;
}

/* ── Bean card ── */

.bean-card {
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 22px;
  padding: 16px;
  margin-bottom: 14px;
  position: relative;
}

.card-menu-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 2px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-right: 34px;
}

.card-top-left { flex: 1; }

.card-name {
  font-family: 'Bricolage Grotesque', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
  margin-bottom: 2px;
}

.card-location {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  opacity: 0.65;
  margin-bottom: 6px;
}

.card-varieties {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.card-top-right {
  padding-left: 12px;
  text-align: right;
}

.card-grams {
  font-family: 'Bricolage Grotesque', Georgia, serif;
  font-size: 24px;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
}

.card-grams-of {
  font-size: 14px;
  font-weight: 500;
  opacity: 0.5;
}

.card-roast {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  margin-bottom: 2px;
}

.card-roast-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}

.card-progress {
  height: 8px;
  background: var(--track);
  border-radius: 4px;
  margin: 10px 0 12px;
  overflow: hidden;
}

.card-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
}

.card-footer {
  margin-top: 10px;
}

.card-untracked {
  font-size: 12px;
  color: var(--ink);
  opacity: 0.5;
  margin-bottom: 8px;
}

.card-action {
  width: 100%;
  height: 44px;
  background: var(--accent);
  color: var(--ink);
  border: none;
  border-radius: 14px;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.card-action--disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Roast dot ── */

.roast-dot {
  display: inline-block;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  flex-shrink: 0;
}

.roast-dot--card { width: 14px; height: 14px; }
.roast-dot--bar  { width: 16px; height: 16px; }

/* ── Chips ── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--frozen-bg);
  border: 1.5px solid var(--accent);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.chip--sm {
  font-size: 12px;
  padding: 2px 8px;
}

.chip-x {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.5;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
}

.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.chip-input {
  flex: 1;
  min-width: 100px;
}

/* ── Bottom sheet ── */

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 27, 75, 0.55);
  z-index: 100;
  display: flex;
  align-items: flex-end;
}

.sheet {
  background: var(--surface);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
}

.sheet-grabber {
  width: 36px;
  height: 4px;
  background: var(--track);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.sheet-title {
  font-family: 'Bricolage Grotesque', Georgia, serif;
  font-size: 28px;
  font-weight: 800;
  color: var(--ink);
  flex: 1;
  padding-right: 12px;
}

.sheet-close {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--frozen-bg);
  border: none;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  flex-shrink: 0;
}

.menu-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-row {
  width: 100%;
  min-height: 64px;
  background: none;
  border: 1.5px solid var(--accent);
  border-radius: 18px;
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
}

.menu-row-body { flex: 1; }

.menu-row-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 2px;
}

.menu-row-desc {
  font-size: 13px;
  color: var(--ink);
  opacity: 0.55;
}

.archive-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.archive-prompt {
  font-size: 16px;
  color: var(--ink);
  font-weight: 500;
}

.star-row {
  display: flex;
  gap: 4px;
}

.star-btn {
  width: 52px;
  height: 52px;
  background: none;
  border: none;
  font-size: 32px;
  cursor: pointer;
  color: var(--track);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.star-btn--on { color: var(--primary); }

.archive-confirm {
  width: 100%;
  max-width: 100%;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--ink);
  opacity: 0.5;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 15px;
  cursor: pointer;
  padding: 8px 0;
}

/* ── Form styles ── */

.form-section {
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 22px;
  padding: 16px;
  margin-bottom: 14px;
}

.form-section-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.form-section-title {
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 12px;
}

.form-section-hd .form-section-title { margin-bottom: 0; }

.form-remove-btn {
  background: none;
  border: none;
  color: var(--ink);
  opacity: 0.45;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 0;
}

.form-field {
  margin-bottom: 12px;
}

.form-field:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 6px;
}

.form-req {
  color: var(--primary);
  font-weight: 700;
}

.form-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 12px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.form-input:focus { border-color: var(--primary); }
.form-input--err  { border-color: #e74c3c; }
.form-input:disabled { background: var(--frozen-bg); opacity: 0.5; }

.form-textarea {
  height: 88px;
  padding: 12px 14px;
  resize: none;
}

.form-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-hint {
  font-size: 12px;
  color: var(--ink);
  opacity: 0.5;
  margin-top: 5px;
}

.form-error {
  font-size: 13px;
  color: #e74c3c;
  margin-top: 5px;
}

.form-error--global {
  text-align: center;
  margin-bottom: 12px;
}

.form-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.form-switch {
  width: 52px;
  height: 30px;
  border-radius: 15px;
  background: var(--track);
  border: none;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}

.form-switch::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  background: #ffffff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}

.form-switch--on { background: var(--primary); }
.form-switch--on::after { transform: translateX(22px); }

.form-add-origin {
  width: 100%;
  height: 52px;
  background: none;
  border: 1.5px dashed var(--accent);
  border-radius: 18px;
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  margin-bottom: 14px;
}

.origin-form { display: flex; flex-direction: column; gap: 10px; }

.code-panel {
  background: var(--blush);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 16px;
  text-align: center;
}

.code-panel-text {
  font-size: 13px;
  color: var(--ink);
  opacity: 0.7;
  line-height: 1.5;
}

.form-submit {
  width: 100%;
  max-width: 100%;
  margin-bottom: 32px;
}

/* ── RoastBar ── */

.roast-bar-wrap { margin-bottom: 4px; }

.roast-bar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  min-height: 24px;
}

.roast-bar-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.roast-bar-unset {
  font-size: 13px;
  color: var(--ink);
  opacity: 0.45;
}

.roast-bar-track { position: relative; height: 24px; }

.roast-range {
  -webkit-appearance: none;
  width: 100%;
  height: 20px;
  margin: 2px 0;
  background: linear-gradient(
    to right,
    var(--fill) 0%,
    var(--fill) var(--pct),
    var(--frozen-bg) var(--pct),
    var(--frozen-bg) 100%
  );
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  outline: none;
  cursor: pointer;
}

.roast-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  background: #ffffff;
  border: 3px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
  margin-top: -4px;
}

.roast-range::-moz-range-thumb {
  width: 28px;
  height: 28px;
  background: #ffffff;
  border: 3px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
}

.roast-range::-webkit-slider-runnable-track {
  height: 20px;
  border-radius: 10px;
}

.roast-bar-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink);
  opacity: 0.45;
  margin-top: 6px;
}
