:root {
  --bg-main: #101012;
  --bg-card: #18181c;
  --bg-subtle: #222228;
  --bg-hover: #2c2c34;
  --border: #2e2e38;
  --border-focus: #c2956c;
  --text-primary: #f4f4f6;
  --text-secondary: #9a9aa8;
  --text-muted: #666675;
  --accent: #d4a373;
  --accent-light: #e6ccb2;
  --accent-dark: #b07d50;
  --accent-glow: rgba(212, 163, 115, 0.16);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  justify-content: center;
}

.app-container {
  width: 100%;
  max-width: 540px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--bg-main);
}

.hidden {
  display: none !important;
}

/* ---------------- Auth View ---------------- */
#auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.auth-card .brand-icon {
  font-size: 3rem;
  display: inline-block;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 12px rgba(212, 163, 115, 0.3));
}

.auth-card h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.auth-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 4px;
  margin-bottom: 24px;
}

.auth-form .input-group {
  text-align: left;
  margin-bottom: 16px;
}

.auth-form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.auth-form input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.1rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  letter-spacing: 0.1em;
  text-align: center;
  outline: none;
  transition: all 0.2s ease;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.hint-text {
  font-size: 0.82rem;
  color: var(--accent);
  margin-bottom: 16px;
  text-align: center;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 12px;
  font-weight: 500;
}

/* ---------------- Main View ---------------- */
#main-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100vh;
  overflow: hidden;
}

.app-header {
  padding: calc(var(--safe-top) + 14px) 16px 10px 16px;
  background: rgba(16, 16, 18, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.logo-emoji {
  font-size: 1.4rem;
}

.logo-text {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn svg {
  flex-shrink: 0;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--accent-light);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Scroll Area */
.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(var(--safe-bottom) + 32px) 16px;
  -webkit-overflow-scrolling: touch;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* ---------------- Quick Beans Pills ---------------- */
.pills-wrapper {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pill-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.pills-container {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.pills-container::-webkit-scrollbar {
  display: none;
}

.bean-pill {
  flex-shrink: 0;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.bean-pill:hover, .bean-pill:active {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent-light);
}

/* ---------------- Form & Inputs ---------------- */
.brew-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.field-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-wrap.full {
  flex: 1;
}

.field-wrap label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.optional-tag {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: none;
}

input[type="text"],
input[type="date"] {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
  width: 100%;
}

input[type="date"] {
  color-scheme: dark;
}

input[type="text"]:focus,
input[type="date"]:focus {
  border-color: var(--accent);
}

/* Preset Banner */
.preset-banner {
  background: rgba(212, 163, 115, 0.1);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.preset-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preset-title {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}

.preset-values {
  font-size: 0.85rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.btn-preset-apply {
  background: var(--accent);
  color: #1a1510;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* Parameters Grid */
.params-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.param-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.param-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.param-header label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.param-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stepper-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.step-btn {
  width: 38px;
  height: 42px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
  transition: all 0.15s ease;
}

.step-btn:active {
  background: var(--bg-hover);
  transform: scale(0.95);
}

.stepper-control input {
  flex: 1;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent-light);
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  height: 42px;
  outline: none;
  -moz-appearance: textfield;
}

.stepper-control input::-webkit-outer-spin-button,
.stepper-control input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.quick-chips {
  display: flex;
  gap: 4px;
}

.chip {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  color: var(--text-secondary);
  border-radius: 4px;
  padding: 4px 2px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.chip:hover, .chip:active {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border);
}

/* Stopwatch Widget */
.timer-widget {
  margin-top: 2px;
}

.timer-btn {
  width: 100%;
  background: rgba(212, 163, 115, 0.12);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent-light);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.timer-btn.running {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger);
  color: #fca5a5;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.75; }
  100% { opacity: 1; }
}

.ratio-badge {
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-align: center;
}

.ratio-badge strong {
  color: var(--accent);
  font-family: var(--font-mono);
}

/* ---------------- Rating Section ---------------- */
.rating-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rating-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rating-header label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.rating-score {
  font-size: 1.25rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.rating-total {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.rating-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.rating-poor {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.rating-drinkable {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.rating-good {
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.rating-perfect {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.rating-slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 8px;
  background: var(--bg-card);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #121214;
  box-shadow: 0 0 10px rgba(212, 163, 115, 0.6);
  cursor: pointer;
}

.rating-scale-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
}

.rating-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--accent);
  color: #181512;
}

.btn-primary:hover, .btn-primary:active {
  background: var(--accent-light);
}

.btn-save {
  background: linear-gradient(135deg, #d4a373 0%, #b07d50 100%);
  color: #12100e;
  box-shadow: 0 4px 14px rgba(212, 163, 115, 0.25);
  margin-top: 4px;
}

.btn-save:active {
  transform: scale(0.98);
}

.full-width {
  width: 100%;
}

.feedback-msg {
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  text-align: center;
  font-weight: 600;
}

.feedback-msg.success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.feedback-msg.error {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ---------------- My Beans & History List ---------------- */
.section-header {
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.section-header p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.beans-grid,
.history-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

/* Bean Card */
.bean-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s ease;
}

.bean-card:hover {
  border-color: rgba(212, 163, 115, 0.4);
}

.bean-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.bean-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.bean-meta-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.bean-dial-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  gap: 6px;
  text-align: center;
}

.dial-stat-item {
  display: flex;
  flex-direction: column;
}

.dial-stat-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.dial-stat-val {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--accent-light);
}

.bean-card-actions {
  display: flex;
  justify-content: flex-end;
}

.btn-card-use {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-card-use:hover {
  background: var(--accent);
  color: #12100e;
}

/* History Shot Card */
.shot-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shot-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.shot-coffee {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.shot-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.shot-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.shot-stats span strong {
  color: var(--text-primary);
}

.shot-notes {
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent);
}

.shot-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
}

.btn-delete-shot {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.15s ease;
}

.btn-delete-shot:hover {
  color: var(--danger);
}
