:root {
  color-scheme: light;
  --ink: #18322d;
  --muted: #6d7f78;
  --line: #d9e4de;
  --paper: #ffffff;
  --canvas: #f1f5f2;
  --green: #267363;
  --green-dark: #1d5b4f;
  --green-wash: #e6f1eb;
  --coral: #bc6347;
  --blue: #547f91;
  --focus: #2e806e;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 6% 0%, rgb(220 237 226 / 48%), transparent 34rem),
    linear-gradient(160deg, #f5f7f6 0%, #f8f8f5 52%, #edf2f2 100%);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[role="option"]:focus-visible {
  outline: 3px solid rgb(46 128 110 / 30%);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.page-width {
  width: min(1080px, calc(100% - 56px));
  margin-inline: auto;
}

.site-header {
  position: relative;
  display: flex;
  min-height: 100px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgb(162 184 171 / 54%);
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-copy {
  display: grid;
  gap: 2px;
}

.brand-kicker {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.brand-name {
  font-size: 20px;
  font-weight: 720;
  line-height: 1.15;
}

.brand-domain {
  color: var(--blue);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
}

.brand:hover .brand-domain {
  color: var(--green-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.share-button,
.edit-button,
.save-button,
.secondary-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 650;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.share-button {
  padding: 0 13px;
  border-color: #b7d4c5;
  color: var(--green-dark);
  background: #f7fbf8;
}

.share-button:hover {
  border-color: var(--green);
  background: var(--green-wash);
}

.share-button svg {
  width: 22px;
  height: 22px;
  color: #20a162;
}

main {
  padding: 10px 0 44px;
}

.official-disclaimer {
  margin: 0 0 4px;
  color: var(--coral);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
}

.market-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--coral);
  font-size: 11px;
  font-weight: 750;
}

.market-heading h1 {
  margin: 0;
  font-weight: 700;
}

.market-heading > div:first-child {
  min-width: 0;
  flex: 1 1 220px;
}

.market-heading h1 {
  font-size: 20px;
  line-height: 1.3;
}

.connection-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--green);
  font-size: 12px;
  white-space: nowrap;
}

.connection-state.is-error,
.connection-state .is-error {
  color: var(--coral);
}

.filters {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  align-items: end;
  gap: 18px;
  margin-top: 0;
  padding: 17px 0 19px;
  border-bottom: 1px solid var(--line);
}

.view-tabs {
  display: grid;
  min-height: 43px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid #cbdad1;
  border-radius: 5px;
  background: #eaf0ec;
}

.view-tab {
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 650;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.view-tab:hover:not([aria-selected="true"]) {
  color: var(--ink);
  background: rgb(255 255 255 / 55%);
}

.view-tab[aria-selected="true"] {
  border-color: #b7d4c5;
  color: var(--green-dark);
  background: var(--paper);
}

.view-filter-panel {
  grid-column: 1 / -1;
}

.filter-field {
  display: grid;
  min-width: 0;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.server-picker {
  position: relative;
  display: block;
  min-width: 0;
  flex: 1;
}

.server-control {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
}

.add-server-button,
.dialog-close-button {
  display: grid;
  width: 43px;
  min-width: 43px;
  min-height: 43px;
  place-items: center;
  padding: 0;
  border: 1px solid #b7d4c5;
  border-radius: 5px;
  color: var(--green-dark);
  background: #f7fbf8;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.add-server-button:hover,
.dialog-close-button:hover {
  border-color: var(--green);
  background: var(--green-wash);
}

.add-server-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.server-group-dialog {
  width: min(460px, calc(100% - 32px));
  max-width: 100%;
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 20px 60px rgb(24 50 45 / 20%);
}

.server-group-dialog::backdrop {
  background: rgb(19 39 34 / 42%);
  backdrop-filter: blur(2px);
}

.server-group-form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.dialog-heading h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.dialog-close-button {
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  border-color: var(--line);
  background: #fff;
}

.dialog-close-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.7;
}

.dialog-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.dialog-field input {
  width: 100%;
  min-height: 44px;
  padding: 0 11px;
  border: 1px solid #cbdad1;
  border-radius: 5px;
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
}

.dialog-field input::placeholder {
  color: #99a7a0;
}

.dialog-hint,
.dialog-error {
  margin: -7px 0 0;
  font-size: 12px;
  line-height: 1.7;
}

.dialog-hint {
  color: var(--muted);
}

.dialog-error {
  color: var(--coral);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-actions .save-button,
.dialog-actions .secondary-button {
  min-height: 40px;
  padding: 0 14px;
}

.filter-field input,
.filter-field select,
.price-input {
  width: 100%;
  min-height: 43px;
  border: 1px solid #cbdad1;
  border-radius: 5px;
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
}

.filter-field input,
.filter-field select {
  padding: 0 12px;
}

.filter-field input::placeholder {
  color: #99a7a0;
}

.filter-field select {
  cursor: pointer;
}

.server-options {
  position: absolute;
  z-index: 5;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
  box-shadow: 0 12px 28px rgb(24 50 45 / 12%);
  list-style: none;
}

.server-options li {
  padding: 10px 9px;
  border-radius: 3px;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
}

.server-options li:hover,
.server-options li[aria-selected="true"] {
  color: var(--green-dark);
  background: var(--green-wash);
}

.update-summary {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 8px;
  padding: 1px 0 3px 12px;
  border-left: 2px solid #a7c1cd;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.update-summary strong {
  color: var(--blue);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.recent-section {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 9px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.recent-section h2 {
  flex: 0 0 auto;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.recent-list {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.recent-item {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--green-dark);
  background: var(--paper);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.recent-item:hover {
  border-color: #a7c9b8;
  background: var(--green-wash);
}

.market-section {
  padding-top: 26px;
}

.market-ad {
  margin: 24px 0 32px;
}

.market-heading {
  align-items: center;
  padding-bottom: 14px;
}

.price-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.price-warning {
  margin: 4px 0 0;
  color: var(--coral);
  font-size: 11px;
  line-height: 1.5;
}

.market-updates {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: 28px;
  border-top: 1px solid var(--line);
}

.city-rank-table {
  border-top: 1px solid var(--line);
}

.city-rank-header,
.city-rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(100px, max-content) minmax(90px, max-content);
  align-items: center;
  gap: 12px;
}

.city-rank-header {
  min-height: 38px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.city-rank-header span:nth-child(n + 2) {
  text-align: right;
}

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

.city-rank-row {
  min-height: 50px;
  border-bottom: 1px solid var(--line);
  animation: row-in 220ms ease both;
}

.rank-city {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
}

.rank-number {
  display: grid;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 3px;
  color: var(--green-dark);
  background: var(--green-wash);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.city-rank-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 550;
}

.city-rank-price {
  color: var(--green-dark);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.city-rank-updated {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
  white-space: nowrap;
}

.product-row {
  display: flex;
  min-width: 0;
  min-height: 50px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  animation: row-in 220ms ease both;
}

.product-row:nth-child(3n + 2) {
  animation-delay: 25ms;
}

.product-row:nth-child(3n) {
  animation-delay: 45ms;
}

.product-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 550;
}

.product-price {
  flex: 0 0 auto;
  color: var(--green-dark);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.price-input {
  width: min(120px, 42%);
  min-height: 36px;
  padding: 0 9px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-state,
.request-error {
  margin: 0;
  padding: 25px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.empty-logo {
  display: block;
  width: min(320px, 70vw);
  margin: 4px auto 0;
  animation: row-in 220ms ease both;
}

.request-error {
  color: var(--coral);
}

.edit-hint {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.edit-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.edit-button,
.save-button {
  padding: 0 15px;
  color: #fff;
  background: var(--green);
}

.edit-button:hover,
.save-button:hover:not(:disabled) {
  background: var(--green-dark);
}

.secondary-button {
  padding: 0 14px;
  border-color: #cbdad1;
  color: var(--ink);
  background: var(--paper);
}

.secondary-button:hover {
  background: #f7faf8;
}

.site-footer {
  padding: 18px 0 30px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
  text-align: center;
}

.site-footer p {
  margin: 2px 0;
}

.toast {
  position: fixed;
  z-index: 10;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  max-width: min(420px, calc(100vw - 40px));
  padding: 11px 15px;
  border: 1px solid #c5d8cd;
  border-radius: 5px;
  color: #fff;
  background: #244f45;
  box-shadow: 0 8px 24px rgb(24 50 45 / 18%);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(7px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 780px) {
  .page-width {
    width: min(100% - 36px, 620px);
  }

  .site-header {
    min-height: 84px;
  }

  .brand-logo {
    width: 50px;
    height: 50px;
  }

  .filters {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: 13px;
  }

  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 20px;
  }
}

@media (max-width: 520px) {
  .page-width {
    width: calc(100% - 32px);
  }

  .site-header {
    min-height: 76px;
  }

  .brand {
    gap: 8px;
  }

  .brand-logo {
    width: 44px;
    height: 44px;
  }

  .brand-name {
    font-size: 18px;
  }

  .brand-kicker {
    font-size: 10px;
  }

  .brand-domain {
    font-size: 10px;
  }

  .share-button {
    min-height: 39px;
    gap: 5px;
    padding: 0 9px;
    font-size: 12px;
  }

  .share-button svg {
    width: 20px;
    height: 20px;
  }

  main {
    padding: 12px 0 33px;
  }

  .connection-state {
    gap: 5px;
    font-size: 10px;
  }

  #connection-status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .filters {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 14px 0;
  }

  .city-rank-header,
  .city-rank-row {
    grid-template-columns: minmax(0, 1fr) minmax(84px, max-content) minmax(76px, max-content);
    gap: 8px;
  }

  .rank-city {
    gap: 6px;
  }

  .rank-number {
    width: 20px;
    height: 22px;
  }

  .city-rank-name {
    font-size: 12px;
  }

  .city-rank-price {
    font-size: 13px;
  }

  .city-rank-updated {
    font-size: 10px;
  }

  .market-updates {
    gap: 8px;
    padding-bottom: 11px;
  }

  .update-summary {
    gap: 6px;
    padding-left: 9px;
    font-size: 10px;
  }

  .update-summary strong {
    font-size: 12px;
  }

  .filter-field input,
  .filter-field select,
  .dialog-field input {
    font-size: 16px;
  }

  .market-section {
    padding-top: 21px;
  }

  .market-heading {
    align-items: flex-start;
    gap: 10px;
    padding-bottom: 11px;
  }

  .product-grid {
    grid-template-columns: minmax(0, 1fr);
    column-gap: 0;
  }

  .product-row {
    min-height: 47px;
  }

  .product-name {
    font-size: 13px;
  }

  .product-price {
    font-size: 16px;
  }

  .edit-actions {
    width: auto;
    margin-left: auto;
  }

  .edit-button,
  .save-button,
  .secondary-button {
    min-height: 40px;
    padding: 0 11px;
    font-size: 12px;
  }

  .site-footer {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}