:root {
  --bg: #f3efe9;
  --panel: #fbf8f4;
  --panel-soft: #f0ebe3;
  --primary: #2d5c4f;
  --primary-dark: #21493d;
  --primary-soft: #deefe7;
  --text: #1f2321;
  --muted: #5d625f;
  --line: #1d221f;
  --danger: #7a8b82;
  --danger-soft: #edf0ee;
  --success: #3d715d;
  --bottom: #f7f3ee;
  --shadow: rgba(21, 24, 22, 0.04);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0.01em;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: 100vw;
  max-width: 100vw;
  min-height: 100vh;
  height: 100vh;
  background: var(--bg);
  padding: 18px 0 0;
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 0;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0 14px 0;
}

.shopping-list {
  list-style: none;
  padding: 0 0 10px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  flex: 1;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px 14px 14px;
  background: var(--panel);
  border: 2px solid var(--line);
  min-height: 80px;
  box-shadow: 0 1px 0 var(--shadow);
}

.item-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.check-box {
  width: 30px;
  height: 30px;
  border: 3px solid var(--line);
  background: #fff;
  appearance: none;
  position: relative;
  flex-shrink: 0;
}

.check-box:checked {
  background: var(--success);
  border-color: var(--success);
}

.check-box:checked::after {
  content: "✓";
  color: #fff;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  font-weight: 700;
}

.item-copy {
  min-width: 0;
  flex: 1;
}

.item-name {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.item-name.checked {
  text-decoration: line-through;
  color: var(--muted);
}

.item-qty {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 8px;
  background: var(--primary-soft);
  border: 2px solid var(--line);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.item-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.delete-btn,
.square-btn,
.primary-btn,
.ghost-btn,
.text-btn {
  border: 2px solid var(--line);
  background: #fff;
  color: var(--text);
  font-weight: 700;
  transition: transform 0.15s ease;
}

.delete-btn:active,
.square-btn:active,
.primary-btn:active,
.ghost-btn:active,
.text-btn:active {
  transform: translateY(1px);
}

.delete-btn {
  min-width: 64px;
  min-height: 36px;
  padding: 8px 10px;
  font-size: 0.74rem;
  text-transform: uppercase;
  background: var(--panel-soft);
  color: var(--text);
}

.empty-state {
  display: none;
  text-align: center;
  margin: auto 0;
  padding: 44px 18px;
  border: 3px dashed var(--line);
  background: rgba(255, 255, 255, 0.18);
  font-weight: 700;
  color: var(--muted);
}

.empty-state.visible {
  display: block;
}

.composer {
  position: sticky;
  bottom: 0;
  left: 0;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  background: var(--bottom);
  border-top: 2px solid var(--line);
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 0 rgba(0, 0, 0, 0.02);
  z-index: 10;
}

.composer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.composer-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

#itemInput {
  width: 100%;
  min-width: 0;
  height: 58px;
  border: 2px solid var(--line);
  background: #fff;
  padding: 0 16px;
  font-size: 1.1rem;
}

#itemInput:focus,
#quantityInput:focus {
  outline: 3px solid rgba(43, 122, 87, 0.2);
}

.quantity-box {
  display: flex;
  align-items: center;
  border: 2px solid var(--line);
  background: #fff;
  overflow: hidden;
  flex-shrink: 0;
}

.square-btn {
  width: 40px;
  height: 52px;
  font-size: 1.7rem;
  line-height: 1;
  background: var(--panel-soft);
  border: none;
  border-right: 1px solid var(--line);
}

.square-btn:last-child {
  border-right: none;
  border-left: 1px solid var(--line);
}

#quantityInput {
  width: 52px;
  height: 52px;
  border: none;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  background: #fff;
  appearance: textfield;
  -moz-appearance: textfield;
}

#quantityInput::-webkit-outer-spin-button,
#quantityInput::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.primary-btn {
  width: 100%;
  height: 56px;
  margin-top: 12px;
  font-size: 1.1rem;
  background: var(--primary);
  color: #fff;
  border: 2px solid var(--line);
}

@media (min-width: 700px) {
  .app-shell {
    padding-bottom: 0;
  }
}

@media (max-height: 640px) {
  .app-shell {
    padding-top: 12px;
  }

  .list-item {
    min-height: 68px;
  }
}
