:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --ink: #2b2b26;
  --ink-sub: #6b6b62;
  --accent: #3c4e33;
  --accent-light: #eef1e8;
  --border: #e0ddd2;
  --danger: #b3453b;
  --matcha: #b7cf97;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c19;
    --surface: #27271f;
    --ink: #ece9df;
    --ink-sub: #a7a496;
    --accent: #9db98a;
    --accent-light: #33392c;
    --border: #3a3a30;
    --danger: #e08a80;
    --matcha: #7f9c62;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 96px;
  min-height: 100vh;
}

.app-header {
  padding: env(safe-area-inset-top, 16px) 20px 14px;
  background: var(--accent);
  color: #fff;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.05em;
}

.app-header .subtitle {
  margin: 4px 0 0;
  font-size: 0.75rem;
  opacity: 0.8;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

.summary {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
  text-align: center;
  margin-bottom: 18px;
}

.summary-label {
  font-size: 0.8rem;
  color: var(--ink-sub);
}

.summary-total {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  margin: 4px 0;
}

.summary-sub {
  font-size: 0.8rem;
  color: var(--ink-sub);
}

.clear-all-button {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 40px;
  height: 26px;
  border-radius: 8px;
  border: none;
  background: var(--matcha);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.clear-all-button:active {
  transform: scale(0.94);
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.item-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}

.item-name {
  font-weight: 600;
  font-size: 1rem;
  word-break: break-word;
}

.item-price {
  font-size: 0.8rem;
  color: var(--ink-sub);
  white-space: nowrap;
}

.item-card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stock-control {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-light);
  border-radius: 10px;
  padding: 4px;
}

.stock-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--surface);
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stock-btn:active {
  transform: scale(0.94);
}

.stock-value {
  min-width: 2.2em;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
}

.item-subtotal {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.95rem;
  white-space: nowrap;
}

.item-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--ink-sub);
  font-size: 1.1rem;
  padding: 6px;
  line-height: 1;
}

.icon-btn.danger {
  color: var(--danger);
}

.icon-btn:disabled {
  opacity: 0.3;
}

.empty-message {
  text-align: center;
  color: var(--ink-sub);
  font-size: 0.85rem;
  padding: 40px 0;
}

.add-button {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  max-width: 448px;
  margin: 0 auto;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.add-button:active {
  transform: scale(0.98);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}

.overlay[hidden] {
  display: none;
}

.form-card {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom, 0px));
}

.form-card h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

#itemForm label {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-sub);
  margin-bottom: 14px;
}

#itemForm input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-size: 1rem;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.form-actions button {
  flex: 1;
  padding: 13px;
  border-radius: 10px;
  border: none;
  font-size: 0.95rem;
  font-weight: 700;
}

.btn-secondary {
  background: var(--accent-light);
  color: var(--ink);
}

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