@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800;900&display=swap');

:root {
  --bg: #121212;
  --panel: #1e1e1e;
  --accent: #ff4757;
  --text: #f1f2f6;
  --muted: #a4b0be;
  --success: #2ed573;
  --stove: #ff6348;
  --fridge-a: #1e90ff;
  --fridge-b: #ffa502;
}

* {
  box-sizing: border-box;
  font-family: 'Inter', sans-serif;
  user-select: none;
}

body {
  margin: 0;
  padding: 10px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* changed from height: 100vh */
  overflow-y: auto;
  /* changed from overflow: hidden to allow scrolling the whole page if needed */
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  padding: 10px;
  /* reduced from 15px */
  border-radius: 12px;
  margin-bottom: 8px;
  /* reduced from 10px */
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.menu-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  /* reduced from 5px */
}

.progress {
  font-size: 0.95rem;
  /* reduced from 1.1rem */
  color: var(--muted);
  font-weight: 600;
}

.bill-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-start;
  margin-top: 5px;
}

.bill-item {
  flex: 1;
  min-width: 150px;
  max-width: 250px;
  font-size: 1.0rem;
  font-weight: 900;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  padding: 8px 12px;
  border-radius: 8px;
  border-left: 6px solid var(--accent);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  position: relative;
  transition: 0.3s;
}

.bill-item::before {
  content: attr(data-pan);
  position: absolute;
  top: -10px;
  left: -5px;
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.bill-item.done {
  text-decoration: line-through;
  color: var(--muted);
  border-left-color: var(--success);
  opacity: 0.5;
}

.menu-name {
  font-size: 1.6rem;
  /* reduced from 2rem */
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  word-break: keep-all;
  display: none;
}

.center-hud {
  flex: 1;
  text-align: center;
}

.timer {
  font-size: 2.2rem;
  /* reduced from 3rem */
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  text-shadow: 0 0 10px rgba(255, 71, 87, 0.4);
}

.controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* reduced from 8px */
  align-items: flex-end;
  justify-content: center;
}

.mode-selector {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  overflow: hidden;
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 10px;
  /* reduced from 8px 12px */
  font-size: 0.85rem;
  /* added */
  font-weight: 800;
  cursor: pointer;
  transition: 0.2s;
}

.mode-btn.active {
  background: var(--panel);
  color: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}

.btn-group {
  display: flex;
  gap: 8px;
  /* reduced from 10px */
}

.btn {
  padding: 8px 12px;
  /* reduced from 12px 16px */
  border: none;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.85rem;
  /* reduced from 1rem */
  cursor: pointer;
  transition: 0.1s;
  color: white;
}

.btn:active {
  transform: scale(0.95);
}

.btn-start {
  background: var(--success);
}

.btn-stats {
  background: #3742fa;
}

/* Main Grid */
.main-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: minmax(200px, 1fr) auto;
  /* reduced from 300px */
  gap: 8px;
  /* reduced from 12px */
  flex: 1;
}

/* Pan Area */
.pan {
  grid-column: 1;
  grid-row: 1;
  background: #2f3542;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.pan-tabs {
  display: flex;
  background: #1e242d;
}

.pan-tab {
  flex: 1;
  padding: 6px;
  /* reduced from 10px */
  font-size: 0.9rem;
  /* added */
  text-align: center;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
  transition: 0.2s;
  border-bottom: 3px solid transparent;
}

.pan-tab.active {
  color: #fff;
  background: #2f3542;
  border-bottom-color: var(--accent);
}

.pan-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* reduced from 8px */
  overflow-y: auto;
  padding: 10px;
  /* reduced from 15px */
}

.pan-zone {
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 8px;
  /* reduced from 10px */
  border-left: 4px solid #576574;
}

.zone-label {
  font-size: 0.85rem;
  /* reduced from 0.95rem */
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 6px;
  /* reduced from 8px */
}

.zone-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  /* reduced from 6px */
  min-height: 32px;
  /* reduced from 38px */
}

.pan-controls {
  padding: 8px 10px;
  display: flex;
  gap: 8px;
  background: rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-clear {
  background: #576574;
  color: white;
  border: none;
  padding: 10px;
  /* reduced from 15px */
  border-radius: 8px;
  flex: 1;
  font-weight: 800;
  font-size: 0.9rem;
  /* added */
  cursor: pointer;
}

.btn-submit {
  background: var(--success);
  color: white;
  border: none;
  padding: 10px;
  /* reduced from 15px */
  border-radius: 8px;
  flex: 3;
  font-weight: 900;
  font-size: 1.1rem;
  /* reduced from 1.3rem */
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Stove (Main Ingredients) */
.stove-area {
  grid-column: 2;
  grid-row: 1;
  background: var(--panel);
  border-radius: 12px;
  padding: 10px;
  /* reduced from 15px */
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.stove-area h2 {
  margin-top: 0;
  margin-bottom: 8px;
  /* reduced from 10px */
  color: var(--stove);
  font-size: 1.05rem;
  /* reduced from 1.2rem */
  font-weight: 800;
}

/* Fridges */
.fridges-area-a {
  grid-column: 1;
  grid-row: 2;
}

.fridges-area-b {
  grid-column: 2;
  grid-row: 2;
}

.fridge {
  background: var(--panel);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fridge-header {
  padding: 8px;
  /* reduced from 10px */
  cursor: pointer;
  font-weight: 900;
  font-size: 0.95rem;
  /* reduced from 1.1rem */
  text-align: center;
  background: #2f3542;
  transition: 0.2s;
  color: var(--muted);
  border-bottom: 2px solid #121212;
}

.fridge-header.open {
  background: #576574;
  color: white;
}

.fridge-content {
  padding: 10px;
  flex: 1;
  height: 120px;
  /* fixed height to prevent layout shifts */
  visibility: hidden;
  /* instead of display: none */
  opacity: 0;
  background: #222f3e;
  overflow-y: auto;
  transition: opacity 0.2s;
}

.fridge-content.visible {
  visibility: visible;
  opacity: 1;
}

/* Dict results */
.dict-item {
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
}

.dict-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.dict-item b {
  color: #1dd1a1;
}

/* Ingredient Buttons */
.ing-btn {
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  /* reduced from 0.95rem */
  font-weight: 800;
  padding: 8px 2px;
  /* reduced from 10px 4px */
  cursor: pointer;
  color: #fff;
  transition: transform 0.05s;
  word-break: keep-all;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.ing-btn:active {
  transform: scale(0.92);
}

.stove-btn {
  background: linear-gradient(135deg, var(--stove), #e55039);
}

.fridgea-btn {
  background: linear-gradient(135deg, var(--fridge-a), #5352ed);
}

.fridgeb-btn {
  background: linear-gradient(135deg, var(--fridge-b), #e1b12c);
}

.extra-btn {
  background: linear-gradient(135deg, #a4b0be, #747d8c);
  padding: 6px 10px;
  /* reduced */
}

/* Grid Headers (for Stove Fridge Sections) */
.grid-header {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-weight: 900;
  font-size: 0.95rem;
  /* reduced from 1.1rem */
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
  /* reduced from 5px */
  margin-bottom: 4px;
}

.ing-chip {
  background: #f1f2f6;
  color: #2f3542;
  border-radius: 20px;
  padding: 4px 10px;
  /* reduced from 6px 14px */
  font-weight: 900;
  font-size: 0.85rem;
  /* reduced from 1.0rem */
  display: flex;
  align-items: center;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
  animation: popIn 0.15s ease-out;
  cursor: pointer;
}

.ing-chip:hover {
  background: #ff4757;
  color: white;
}

@keyframes popIn {
  from {
    transform: scale(0.5);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* Feedbacks */
body.flash-error {
  animation: flashRed 0.4s;
}

body.flash-success {
  animation: flashGreen 0.4s;
}

@keyframes flashRed {
  0% {
    background: #ff4757;
  }

  100% {
    background: var(--bg);
  }
}

@keyframes flashGreen {
  0% {
    background: #2ed573;
  }

  100% {
    background: var(--bg);
  }
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: var(--panel);
  padding: 20px;
  /* reduced from 30px */
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
  margin-top: 0;
  font-weight: 900;
  font-size: 1.6rem;
  /* reduced from 2rem */
  color: #fff;
}

.feedback-text {
  font-size: 1.1rem;
  /* reduced from 1.3rem */
  margin: 15px 0;
  /* reduced from 20px */
  color: #ff6b81;
  line-height: 1.5;
  font-weight: 800;
  background: rgba(255, 71, 87, 0.1);
  padding: 15px;
  /* reduced from 20px */
  border-radius: 12px;
  word-break: keep-all;
}

.stats-box {
  text-align: left;
  background: #2f3542;
  padding: 15px;
  /* reduced from 20px */
  border-radius: 12px;
  margin-bottom: 12px;
  /* reduced from 15px */
}

.stats-box h3 {
  margin-top: 0;
  color: var(--accent);
  border-bottom: 2px solid #576574;
  padding-bottom: 8px;
  /* reduced from 10px */
  font-weight: 900;
  font-size: 1.1rem;
  /* added */
}

.stats-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.stats-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  /* reduced from 10px */
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-weight: 600;
  font-size: 0.95rem;
  /* reduced from 1.1rem */
}

.stats-list li:last-child {
  border-bottom: none;
}

.modal-close {
  background: #576574;
  color: white;
  border: none;
  padding: 12px 24px;
  /* reduced from 15px 30px */
  border-radius: 8px;
  font-weight: 900;
  font-size: 1.05rem;
  /* reduced from 1.2rem */
  cursor: pointer;
  margin-top: 15px;
  /* reduced from 20px */
  width: 100%;
  transition: 0.2s;
}

.modal-close:active {
  background: #8395a7;
}

/* Recipe Table Modal Styles */
.recipe-content {
  max-width: 900px !important;
  text-align: left;
}

.group-title {
  margin-top: 20px;
  /* reduced from 30px */
  margin-bottom: 10px;
  /* reduced from 15px */
  color: var(--accent);
  font-weight: 900;
  border-bottom: 2px solid #333;
  padding-bottom: 5px;
  font-size: 1.1rem;
  /* added */
}

.recipe-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 15px;
  /* reduced from 20px */
  font-size: 0.85rem;
  /* reduced from 0.95rem */
}

.recipe-table th {
  background: #2f3542;
  color: #fff;
  padding: 8px;
  /* reduced from 10px */
  text-align: left;
  border: 1px solid #444;
  font-weight: 900;
}

.recipe-table td {
  background: var(--panel);
  padding: 6px;
  /* reduced from 8px */
  border: 1px solid #333;
}

.recipe-table b {
  color: #ffeb3b;
}

/* Mobile UX Overhaul */
.mobile-tabs {
  display: none;
  background: #1e242d;
  margin-bottom: 8px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.mobile-tab-btn {
  flex: 1;
  padding: 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  transition: 0.2s;
  border-bottom: 3px solid transparent;
}

.mobile-tab-btn.active {
  color: #fff;
  background: #2f3542;
  border-bottom-color: var(--accent);
}

@media (max-width: 768px) {
  body {
    padding: 2px;
    height: 100vh;
    overflow: hidden;
  }

  .header {
    flex-direction: column;
    gap: 4px;
    padding: 5px;
    margin-bottom: 5px;
  }

  .progress {
    font-size: 0.8rem;
  }

  .menu-name {
    font-size: 1.2rem;
  }

  .bill-item {
    min-width: 120px;
    font-size: 0.85rem;
    padding: 5px 8px;
  }

  .center-hud {
    order: -1;
    width: 100%;
  }

  .timer {
    font-size: 1.5rem;
  }

  .mode-selector {
    margin-bottom: 4px;
  }

  .mode-btn {
    padding: 4px 8px;
    font-size: 0.75rem;
  }

  .btn-group {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 3px;
  }

  .btn {
    padding: 5px 8px;
    font-size: 0.75rem;
  }

  .main-area {
    display: flex;
    flex-direction: column;
    gap: 0;
    height: calc(100vh - 150px);
    /* Tighter header offset */
    overflow: hidden;
  }

  .mobile-tabs {
    display: flex;
    flex-shrink: 0;
    margin-bottom: 5px;
  }

  .mobile-tab-btn {
    padding: 8px;
    font-size: 0.8rem;
  }

  .pan {
    flex: 0 0 auto;
    height: 250px;
    /* increased to show more content */
    margin-bottom: 5px;
    border-radius: 6px;
  }

  .pan-tab {
    padding: 4px;
    font-size: 0.8rem;
  }

  .pan-content {
    padding: 5px;
  }

  .pan-zone {
    padding: 4px;
  }

  .zone-label {
    font-size: 0.75rem;
    margin-bottom: 3px;
  }

  .ing-chip {
    padding: 2px 6px;
    font-size: 0.75rem;
  }

  /* Mobile Content Switching */
  .stove-area,
  .fridges-area-a,
  .fridges-area-b {
    display: none !important;
    height: 100%;
    overflow-y: auto;
    padding: 5px;
  }

  .main-area.show-stove .stove-area {
    display: flex !important;
  }

  .main-area.show-fridges-a .fridges-area-a {
    display: grid !important;
  }

  .main-area.show-fridges-b .fridges-area-b {
    display: flex !important;
  }

  .fridge-content {
    height: auto;
    min-height: 100px;
    padding: 5px;
  }

  /* Shrink ingredients in grid */
  .grid-container {
    gap: 4px;
  }

  .ing-btn {
    font-size: 0.75rem;
    padding: 6px 2px;
  }

  .grid-header {
    font-size: 0.8rem;
    padding: 2px 0;
  }
}