:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --tile-bg: #f2f2f5;
  --tile-border: #d8d8de;
  --tile-selected-bg: #2f6fed;
  --tile-selected-fg: #ffffff;
  --accent: #2f6fed;
  --bar-bg: #f7f7fa;
  --muted: #666666;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171b;
    --fg: #f0f0f2;
    --tile-bg: #24262c;
    --tile-border: #3a3c44;
    --tile-selected-bg: #4c86ff;
    --tile-selected-fg: #0b0b0d;
    --accent: #4c86ff;
    --bar-bg: #1e2025;
    --muted: #aaaaaa;
  }
}

:root[data-theme="dark"] {
  --bg: #16171b;
  --fg: #f0f0f2;
  --tile-bg: #24262c;
  --tile-border: #3a3c44;
  --tile-selected-bg: #4c86ff;
  --tile-selected-fg: #0b0b0d;
  --accent: #4c86ff;
  --bar-bg: #1e2025;
  --muted: #aaaaaa;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --tile-bg: #f2f2f5;
  --tile-border: #d8d8de;
  --tile-selected-bg: #2f6fed;
  --tile-selected-fg: #ffffff;
  --accent: #2f6fed;
  --bar-bg: #f7f7fa;
  --muted: #666666;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  font-weight: 700;
  font-size: 16px;
}

header {
  padding: 24px 20px 8px;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 8px;
}

.lead {
  font-size: 16px;
  color: var(--muted);
  margin: 0;
}

.selected-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--bar-bg);
  border-bottom: 2px solid var(--tile-border);
}

.selected-label {
  font-size: 16px;
  white-space: nowrap;
}

.selected-list {
  flex: 1 1 200px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
  align-items: center;
}

.selected-list .placeholder {
  color: var(--muted);
  font-size: 15px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--tile-selected-bg);
  color: var(--tile-selected-fg);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 15px;
  font-weight: 700;
}

.chip button {
  border: none;
  background: transparent;
  color: inherit;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

.actions {
  display: flex;
  gap: 10px;
}

.btn {
  font-size: 16px;
  font-weight: 700;
  border-radius: 10px;
  padding: 10px 18px;
  border: 2px solid var(--tile-border);
  background: var(--tile-bg);
  color: var(--fg);
  cursor: pointer;
}

.btn-search {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-search:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-clear:hover,
.btn-search:not(:disabled):hover {
  filter: brightness(1.08);
}

main {
  padding: 20px;
}

.status {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 12px;
}

.status.error {
  color: #d64545;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.tile {
  font-size: 17px;
  font-weight: 700;
  padding: 16px 10px;
  border-radius: 12px;
  border: 2px solid var(--tile-border);
  background: var(--tile-bg);
  color: var(--fg);
  cursor: pointer;
  text-align: center;
  transition: background 0.1s, color 0.1s, transform 0.05s;
}

.tile:active {
  transform: scale(0.97);
}

.tile.selected {
  background: var(--tile-selected-bg);
  color: var(--tile-selected-fg);
  border-color: var(--tile-selected-bg);
}
