:root {
  color-scheme: dark;
  /* iOS system dark palette */
  --bg: #000000;
  --elevated: #1c1c1e;
  --elevated-2: #2c2c2e;
  --field: #1c1c1e;
  --field-focus: #2c2c2e;
  --ink: #f2f2f7;
  --muted: #8e8e93;
  --muted-2: #636366;
  --separator: rgba(84, 84, 88, 0.5);
  --line: rgba(120, 120, 128, 0.45);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.16);
  --danger: #ff453a;
  --danger-soft: rgba(255, 69, 58, 0.16);
  --radius: 16px;
  --radius-sm: 12px;
  --tap: 48px;
}

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

html {
  min-height: 100%;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: var(--tap);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

button:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.shell {
  width: min(100%, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 18px
    max(40px, env(safe-area-inset-bottom));
}

/* ---------- Header / large title ---------- */
.topbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 26px;
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 11vw, 46px);
  line-height: 1.0;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--elevated);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.connection .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.connection.is-online {
  color: #30d158;
}

.connection.is-online .dot {
  background: #30d158;
  box-shadow: 0 0 0 4px rgba(48, 209, 88, 0.18);
}

.connection.is-offline {
  color: var(--danger);
}

.connection.is-offline .dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px var(--danger-soft);
}

/* ---------- Composer card ---------- */
.composer {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--elevated);
}

.field {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  transition: background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.field:focus-within {
  border-color: var(--accent);
}

.field:focus-within {
  background: var(--field-focus);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

input,
textarea {
  width: 100%;
  min-width: 0;
  padding: 14px 16px;
  border: 0;
  outline: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-size: 17px;
}

textarea {
  min-height: 56px;
  resize: none;
  line-height: 1.35;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

#addButton {
  margin-top: 2px;
  font-size: 17px;
  font-weight: 600;
}

/* ---------- Summary ---------- */
.summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 26px 6px 14px;
}

.count {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.count strong {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.count span {
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
}

#clearButton {
  min-height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 15px;
}

/* ---------- Orders grouped list ---------- */
.orders {
  margin-top: 4px;
}

#ordersList {
  display: block;
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--elevated);
  overflow: hidden;
}

#ordersList:empty {
  display: none;
}

.order-row {
  display: grid;
  grid-template-columns: 30px 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 12px 10px;
  background: transparent;
  transition: opacity 0.2s ease;
}

/* ---------- Tick / collected checkbox ---------- */
.tick-button {
  width: 26px;
  height: 26px;
  min-height: 0;
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 14px;
  line-height: 1;
}

.order-row.is-done .tick-button {
  border-color: #30d158;
  background: #30d158;
}

.order-row.is-done .tick-button::after {
  content: "\2713";
}

.order-row.is-done .row-number {
  color: var(--muted-2);
}

.order-row.is-done .name-field,
.order-row.is-done .items-field {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--muted-2);
}

.order-row + .order-row {
  box-shadow: inset 0 1px 0 var(--line);
}

.order-row.is-done {
  opacity: 0.6;
}

.row-number {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.order-fields {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 0 4px;
}

.name-field,
.items-field {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.name-field {
  font-size: 16px;
  font-weight: 600;
}

.items-field {
  min-height: 44px;
  font-size: 15px;
  color: var(--ink);
}

.name-field:focus,
.items-field:focus {
  border-color: var(--accent);
  background: var(--field-focus);
}

.row-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  align-self: center;
}

.duplicate-button,
.remove-button {
  width: 32px;
  height: 32px;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--elevated-2);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}

.duplicate-button {
  color: var(--accent);
}

.duplicate-button:active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.remove-button:active {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------- Empty slot / add another ---------- */
.empty-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
  background: transparent;
  color: var(--accent);
  font-size: 16px;
  font-weight: 500;
}

.empty-slot .plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  font-size: 18px;
  font-weight: 500;
  line-height: 1;
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  .shell {
    padding-inline: 14px;
  }
}