:root {
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe4ee;
  --paper: #fffdf7;
  --surface: #ffffff;
  --sun: #f59e0b;
  --berry: #ef4444;
  --mint: #14b8a6;
  --leaf: #22c55e;
  --blue: #2563eb;
  --shadow: 0 18px 50px rgba(23, 32, 51, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #f4f8fb;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(135deg, rgba(255, 247, 237, 0.8), rgba(239, 246, 255, 0.7) 42%, rgba(240, 253, 244, 0.7)),
    #f4f8fb;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

noscript {
  display: block;
  padding: 24px;
  font-size: 18px;
}

.gate-page {
  min-height: calc(100vh - 42px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: min(440px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.brand,
.week-tools,
.top-actions,
.settings-row,
.tabs,
.picker-head,
.picker-actions,
.picker-footer,
.category-title,
.form-actions,
.row-actions,
.export-toolbar,
.export-actions,
.save-state {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 220px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(135deg, #ef4444, #f59e0b 52%, #14b8a6);
  font-size: 24px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.invite-form {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

.invite-form label,
.settings-row label,
.food-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.invite-form input,
.settings-row input,
.food-form input,
.food-form select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

.invite-form input:focus,
.settings-row input:focus,
.food-form input:focus,
.food-form select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.form-error {
  margin: 0;
  color: #b91c1c;
  font-size: 14px;
}

.app-shell {
  min-height: calc(100vh - 42px);
  padding: 18px;
}

.site-footer {
  min-height: 42px;
  display: grid;
  place-items: center;
  padding: 8px 16px 14px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--ink);
  text-decoration: underline;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 14px;
  border: 1px solid rgba(219, 228, 238, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(18px);
  box-shadow: 0 10px 32px rgba(23, 32, 51, 0.08);
}

.week-tools {
  justify-content: center;
  gap: 10px;
}

.week-range {
  min-width: 170px;
  text-align: center;
}

.week-range span {
  display: block;
  font-size: 20px;
  font-weight: 800;
}

.week-range small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  justify-content: flex-end;
  gap: 10px;
}

.primary-button,
.secondary-button,
.tab-button,
.icon-button,
.food-chip {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease, border-color 150ms ease;
}

.primary-button {
  padding: 0 18px;
  color: #ffffff;
  background: #172033;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(23, 32, 51, 0.16);
}

.secondary-button {
  padding: 0 15px;
  color: var(--ink);
  background: #e8eef6;
  font-weight: 750;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  color: var(--ink);
  background: #edf3f9;
  font-size: 24px;
  font-weight: 800;
}

.icon-button.danger {
  color: #b91c1c;
  background: #fee2e2;
}

.primary-button:hover,
.secondary-button:hover,
.tab-button:hover,
.icon-button:hover,
.food-chip:hover {
  transform: translateY(-1px);
}

.settings-row {
  gap: 12px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid rgba(219, 228, 238, 0.85);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.settings-row label:first-child {
  width: min(230px, 36vw);
}

.settings-row .note-field {
  flex: 1;
}

.save-state {
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--leaf);
}

.tabs {
  gap: 8px;
  margin-bottom: 14px;
}

.tab-button {
  padding: 0 16px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  font-weight: 800;
  border: 1px solid transparent;
}

.tab-button.is-active {
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.08);
}

.main-panel {
  min-height: 500px;
}

.planner-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 390px);
  gap: 14px;
  align-items: start;
}

.mobile-day-strip {
  display: none;
}

.completion-banner {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid #86efac;
  border-radius: 8px;
  background: #f0fdf4;
  box-shadow: 0 10px 24px rgba(22, 101, 52, 0.08);
}

.completion-banner strong {
  color: #14532d;
  font-size: 18px;
}

.week-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.day-card,
.picker-panel,
.food-form,
.library-group,
.export-layout {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 28px rgba(23, 32, 51, 0.08);
}

.day-card {
  min-width: 0;
  min-height: 365px;
  padding: 12px;
  outline: none;
}

.day-card.is-active {
  border-color: #172033;
  box-shadow: 0 16px 38px rgba(23, 32, 51, 0.16);
}

.day-card-head {
  display: grid;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid #edf2f7;
}

.day-card-head strong {
  display: block;
  font-size: 21px;
}

.day-card-head span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.day-card-head em {
  width: fit-content;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.day-card-head .done {
  color: #166534;
  background: #dcfce7;
}

.day-card-head .empty {
  color: #92400e;
  background: #fef3c7;
}

.day-foods {
  display: grid;
  gap: 9px;
  padding-top: 12px;
}

.day-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.day-row p {
  min-height: 34px;
  margin: 4px 0 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
}

.picker-panel {
  position: sticky;
  top: 14px;
  padding: 14px;
}

.picker-head {
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid #edf2f7;
}

.picker-head strong {
  display: block;
  font-size: 24px;
}

.picker-head span {
  display: block;
  color: var(--muted);
}

.picker-day-status {
  display: inline-flex;
  width: fit-content;
  margin-top: 7px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.picker-day-status.done {
  color: #166534;
  background: #dcfce7;
}

.picker-day-status.empty {
  color: #92400e;
  background: #fef3c7;
}

.picker-actions,
.picker-footer,
.export-actions,
.form-actions,
.row-actions {
  gap: 8px;
}

.category-sections {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.spin-panel {
  padding: 14px 0 16px;
  border-bottom: 1px solid #edf2f7;
}

.spin-head {
  display: grid;
  gap: 10px;
}

.spin-head strong {
  display: block;
  font-size: 18px;
}

.spin-head span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.spin-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.spin-tabs button {
  min-height: 34px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 13px;
  font-weight: 800;
}

.spin-tabs button.is-active {
  color: #ffffff;
  border-color: var(--category-color);
  background: var(--category-color);
}

.wheel-wrap {
  position: relative;
  width: 250px;
  height: 250px;
  margin: 14px auto 10px;
}

.wheel-disc {
  position: absolute;
  inset: 0;
  border: 9px solid #ef5b3e;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.75), 0 12px 24px rgba(23, 32, 51, 0.14);
  transform: rotate(var(--rotation));
  transition: transform 1800ms cubic-bezier(0.14, 0.82, 0.2, 1);
}

.wheel-disc::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.65);
  border-radius: 50%;
}

.wheel-pointer {
  position: absolute;
  top: -2px;
  left: 50%;
  z-index: 4;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-right: 15px solid transparent;
  border-left: 15px solid transparent;
  border-top: 0;
  border-bottom: 30px solid #ffffff;
  filter: drop-shadow(0 3px 5px rgba(23, 32, 51, 0.22));
}

.wheel-label {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: var(--label-width, 64px);
  height: 20px;
  margin-top: -10px;
  margin-left: calc(var(--label-width, 64px) / -2);
  overflow: hidden;
  color: #1f2937;
  font-size: 13px;
  font-weight: 900;
  line-height: 20px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.wheel-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 900;
}

.wheel-go {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 5;
  width: 72px;
  height: 72px;
  transform: translate(-50%, -50%);
  border: 5px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  color: #ffffff;
  background: #ff7a45;
  box-shadow: 0 8px 20px rgba(127, 29, 29, 0.22);
  font-size: 24px;
  font-weight: 900;
}

.wheel-result {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  text-align: center;
}

.wheel-result strong {
  flex: 0 0 100%;
  font-size: 17px;
}

.wheel-result span {
  color: var(--muted);
  font-size: 14px;
}

.category-title {
  gap: 8px;
  margin-bottom: 8px;
}

.category-title span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--category-color, var(--sun));
}

.category-title strong {
  font-size: 16px;
}

.category-title small {
  color: var(--muted);
  font-size: 13px;
}

.food-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.food-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 10px;
  color: var(--ink);
  background: #f4f7fb;
  border: 1px solid #e2e8f0;
  font-size: 15px;
  font-weight: 750;
}

.food-chip span {
  font-size: 18px;
}

.food-chip.is-selected {
  color: #ffffff;
  background: var(--category-color, var(--ink));
  border-color: var(--category-color, var(--ink));
  box-shadow: 0 8px 18px rgba(23, 32, 51, 0.14);
}

.food-chip.special {
  border-style: dashed;
}

.picker-footer {
  justify-content: space-between;
  margin-top: 16px;
}

.library-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.food-form {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 12px;
  padding: 16px;
}

.food-form h2,
.export-toolbar h2 {
  margin: 0;
  font-size: 22px;
}

.checkbox-line {
  display: flex !important;
  grid-template-columns: none !important;
  flex-direction: row;
  align-items: center;
  color: var(--ink) !important;
}

.checkbox-line input {
  width: 18px;
  min-height: 18px;
}

.library-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px;
}

.library-group {
  padding: 14px;
}

.library-foods {
  display: grid;
  gap: 8px;
}

.library-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 8px 8px 10px;
  border: 1px solid #edf2f7;
  border-radius: 8px;
  background: #fbfdff;
}

.library-item div:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.library-item b {
  font-size: 20px;
}

.library-item span {
  font-weight: 750;
}

.library-item em {
  padding: 3px 7px;
  border-radius: 999px;
  color: #075985;
  background: #e0f2fe;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.export-layout {
  padding: 16px;
}

.export-toolbar {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.export-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.share-image-button,
.mobile-save-tip {
  display: none;
}

.canvas-frame {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e2e8f0;
  padding: 12px;
}

#export-canvas {
  display: block;
  width: min(100%, 1600px);
  height: auto;
  border-radius: 8px;
  background: #ffffff;
}

.image-save-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(23, 32, 51, 0.72);
  backdrop-filter: blur(8px);
}

.image-save-dialog {
  width: min(920px, 100%);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: 14px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.image-save-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.image-save-head strong {
  font-size: 19px;
}

.image-save-dialog p {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 15px;
}

.image-save-dialog img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: #172033;
  box-shadow: var(--shadow);
  font-weight: 750;
}

.rotate-notice {
  display: none;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .week-tools,
  .top-actions {
    justify-content: flex-start;
  }

  .planner-layout {
    grid-template-columns: 1fr;
  }

  .picker-panel,
  .food-form {
    position: static;
  }

  .week-board {
    display: flex;
    overflow-x: auto;
    padding-bottom: 8px;
    scroll-snap-type: x proximity;
  }

  .day-card {
    flex: 0 0 180px;
    min-height: 310px;
    scroll-snap-align: start;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 8px 8px calc(12px + env(safe-area-inset-bottom));
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 10px;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    gap: 9px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    font-size: 20px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .brand p {
    margin-top: 2px;
    font-size: 12px;
  }

  .top-actions {
    grid-column: 2;
    grid-row: 1;
    gap: 6px;
  }

  .top-actions .primary-button,
  .top-actions .secondary-button {
    min-height: 40px;
    padding: 0 10px;
    font-size: 14px;
  }

  .week-tools {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    justify-content: space-between;
  }

  .week-range {
    min-width: 0;
  }

  .week-range span {
    font-size: 18px;
  }

  .settings-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
    margin: 8px 0;
    padding: 10px;
  }

  .view-planner .settings-row {
    display: none;
  }

  .settings-row label:first-child {
    width: 100%;
  }

  .settings-row input {
    min-height: 42px;
  }

  .save-state {
    font-size: 13px;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
    overflow: visible;
  }

  .tab-button {
    min-width: 0;
    padding: 0 8px;
    white-space: nowrap;
  }

  .planner-layout {
    gap: 8px;
  }

  .completion-banner {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .completion-banner strong {
    font-size: 17px;
  }

  .mobile-day-strip {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 8px 24px rgba(23, 32, 51, 0.07);
  }

  .mobile-day-button {
    position: relative;
    min-width: 0;
    min-height: 64px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 1px;
    padding: 5px 2px 9px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--muted);
    background: #f4f7fb;
  }

  .mobile-day-button strong {
    font-size: 17px;
  }

  .mobile-day-button span {
    max-width: 100%;
    overflow: hidden;
    font-size: 11px;
    text-overflow: clip;
    white-space: nowrap;
  }

  .mobile-day-button i {
    position: absolute;
    right: 5px;
    bottom: 5px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #cbd5e1;
  }

  .mobile-day-button.is-done i {
    background: var(--leaf);
  }

  .mobile-day-button.is-active {
    color: #ffffff;
    border-color: var(--ink);
    background: var(--ink);
    box-shadow: 0 7px 16px rgba(23, 32, 51, 0.18);
  }

  .mobile-day-button.is-active i {
    background: #ffffff;
  }

  .week-board {
    display: none;
  }

  .picker-panel {
    padding: 12px;
  }

  .picker-head strong {
    font-size: 23px;
  }

  .category-sections {
    gap: 18px;
  }

  .category-title {
    margin-bottom: 10px;
  }

  .food-chip-list {
    gap: 8px;
  }

  .food-chip {
    min-height: 44px;
    padding: 0 12px;
    font-size: 16px;
  }

  .picker-footer {
    margin: 18px -12px -12px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .picker-footer > button {
    flex: 1;
  }

  .library-layout,
  .library-list {
    grid-template-columns: 1fr;
  }

  .export-toolbar {
    display: grid;
    align-items: stretch;
    gap: 12px;
  }

  .export-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .export-actions .secondary-button {
    grid-column: 1 / -1;
  }

  .share-image-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-save-tip {
    display: block;
    margin: -2px 0 10px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
  }

  .export-layout {
    padding: 10px;
  }

  .canvas-frame {
    padding: 5px;
  }

  .toast {
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: 10px;
    text-align: center;
  }
}

@media (hover: none) and (pointer: coarse) {
  .share-image-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-save-tip {
    display: block;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .app-shell {
    padding: 8px;
  }

  .topbar {
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    padding: 8px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .brand p,
  .save-state {
    font-size: 12px;
  }

  .settings-row {
    margin: 8px 0;
    padding: 8px;
  }

  .tabs {
    margin-bottom: 8px;
  }

  .day-card {
    min-height: 250px;
  }
}
