: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.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
}

h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  white-space: nowrap;
}

.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);
}

.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;
}

.chip-input {
  flex: 1 1 120px;
  min-width: 120px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 6px 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #2e9e4e;
  color: #ffffff;
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.chip-x {
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
}

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

.fixed-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-left: auto;
}

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

.btn-clear-fixed:hover {
  filter: brightness(1.08);
}

#siteToggleBtn {
  border-color: #2f6fed;
  background: #2f6fed;
  color: #ffffff;
  width: 96px;
  text-align: center;
}

#clearBtn {
  border-color: #d64545;
  background: #d64545;
  color: #ffffff;
}

.tile-special {
  border-color: #e08a2c;
  color: #e08a2c;
  background: var(--tile-bg);
  padding: 10px 16px;
  font-size: 16px;
}

.tile-special.selected {
  background: #2e9e4e;
  border-color: #2e9e4e;
  color: #ffffff;
}

.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: #2e9e4e;
  border-color: #2e9e4e;
  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: 0 20px 20px;
}

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

.status.error {
  color: #d64545;
}

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

.tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  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: #2e9e4e;
  color: #ffffff;
  border-color: #2e9e4e;
}

.tile-text {
  overflow-wrap: anywhere;
}

/* 編集モード：ドラッグ&ドロップ並べ替え・削除・追加
   手本: BOOKMARKリポジトリ Extensions/app.js の onTilePointerDown / animateReorder */

.tiles.edit-mode .tile {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  padding-right: 30px;
}

.tile-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  line-height: 20px;
  border-radius: 999px;
  border: none;
  background: #d64545;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}

.tile-rename-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  padding: 0;
}

.tile.tile-placeholder {
  background: transparent;
  border: 2px dashed var(--tile-border);
}

.tile.dragging {
  position: fixed;
  pointer-events: none;
  transform: scale(1.06);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  will-change: left, top, transform;
}

body.is-dragging,
body.is-dragging * {
  cursor: grabbing !important;
}

.tile-add {
  display: block;
  width: 100%;
  margin-top: 12px;
  border: 2px dashed var(--tile-border);
  background: transparent;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

#editBtn.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}
