:root {
  color-scheme: light;
  --color-bg: #f7f8fa;
  --color-surface: #ffffff;
  --color-border: #dde1e6;
  --color-text: #1c2430;
  --color-text-muted: #5b6472;
  --color-accent: #1f6feb;
  --color-buy: #1a7f37;
  --color-sell: #cf222e;
  --color-highlight-bg: #fff6d8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  line-height: 1.6;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-brand {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.site-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-text);
  text-decoration: none;
}

.site-tagline {
  margin: 0;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.pair-picker {
  position: relative;
  margin-left: auto;
}

.pair-picker-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font: inherit;
  font-size: 0.95rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  max-width: 60vw;
}

.pair-picker-toggle:hover,
.pair-picker-toggle:focus-visible,
.pair-picker-toggle[aria-expanded="true"] {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.pair-picker-toggle-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pair-picker-toggle-icon {
  color: var(--color-text-muted);
  font-size: 0.75em;
}

.pair-panel {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 0.5rem;
  width: min(90vw, 680px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.75rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  z-index: 20;
}

.pair-panel[hidden] {
  display: none;
}

.pair-search-input {
  font-size: 1rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
}

.pair-options {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.2rem;
  max-height: min(60vh, 22rem);
  overflow-y: auto;
}

.pair-options li[hidden] {
  display: none;
}

.pair-options a {
  display: block;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.8rem;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pair-options a:hover,
.pair-options a:focus,
.pair-options a[aria-current="true"] {
  background: var(--color-bg);
  color: var(--color-accent);
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem 0.5rem;
}

.content-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 0.9rem 0.6rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

h1 {
  font-size: 1.3rem;
  margin: 0 0 0.3rem;
}

.pair-intro {
  margin: 0 0 1.2rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.date-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.date-pager button {
  font-size: 0.95rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-accent);
  cursor: pointer;
}

.date-pager button:disabled {
  color: var(--color-text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

#date-label {
  font-weight: 600;
  min-width: 8em;
  text-align: center;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.swap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  white-space: nowrap;
}

.swap-table th,
.swap-table td {
  padding: 0.5rem 0.4rem;
  text-align: right;
  border-bottom: 1px solid var(--color-border);
}

.swap-table th:first-child,
.swap-table td:first-child {
  text-align: left;
}

.swap-table thead th {
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.swap-table tbody tr:last-child td {
  border-bottom: none;
}

.sort-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
}

.sort-button:hover,
.sort-button:focus-visible {
  color: var(--color-accent);
}

.sort-icon {
  display: inline-block;
  font-size: 0.8em;
  color: var(--color-text-muted);
}

.sort-button:hover .sort-icon,
.sort-button:focus-visible .sort-icon {
  color: var(--color-accent);
}

.sort-icon-active {
  color: var(--color-accent);
  font-weight: 700;
}

.broker-cell {
  font-weight: 600;
  max-width: 6.5em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.broker-cell a {
  color: inherit;
  text-decoration: none;
}

.broker-cell a:hover,
.broker-cell a:focus-visible {
  color: var(--color-accent);
  text-decoration: underline;
}

.num-cell:nth-of-type(2) {
  color: var(--color-buy);
}

.num-cell:nth-of-type(3) {
  color: var(--color-sell);
}

.swap-best {
  background: var(--color-highlight-bg);
  font-weight: 700;
  border-radius: 4px;
}

.row-non-jpy {
  color: var(--color-text-muted);
}

.currency-divider td {
  padding: 0.35rem 0.8rem;
  text-align: left;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  white-space: normal;
}

.empty-state {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.site-footer {
  max-width: 900px;
  margin: 2rem auto 1rem;
  padding: 0 1rem;
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

@media (min-width: 640px) {
  main {
    padding: 1.5rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  .content-card {
    padding: 1.25rem;
  }

  .swap-table {
    font-size: 0.95rem;
  }

  .swap-table th,
  .swap-table td {
    padding: 0.6rem 0.8rem;
  }

  .broker-cell {
    max-width: none;
  }
}
