* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0d0f14;
  --bg-soft: #151823;
  --tile: #1a1e2c;
  --tile-hover: #232a3f;
  --border: #2a3044;
  --text: #eef1f8;
  --text-dim: #8b93a7;
  --accent: #6c8cff;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-weight: 700;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(108, 140, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(255, 108, 180, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

/* ===== 編集ボタン（右下固定） ===== */
.edit-toggle {
  position: fixed;
  right: 20px;
  bottom: 20px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 12px 24px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 50;
  transition: all 0.2s;
}

.edit-toggle:hover {
  filter: brightness(1.1);
}

.edit-toggle.active {
  color: #000;
  background: #fff;
  border-color: #fff;
}

/* ===== タイルグリッド ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 11px;
  padding: 24px 24px 80px;
  width: 100%;
  margin: 0;
}

.tile {
  --tile-accent: var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 108px;
  padding: 17px 14px;
  border-radius: 0;
  background: color-mix(in srgb, var(--tile-accent) 55%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--tile-accent) 85%, black 40%);
  text-decoration: none;
  text-align: center;
  word-break: break-word;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, background 0.2s, filter 0.2s;
}

.tile-name {
  font-size: 17px;
  font-weight: 700;
  color: #d6d9e0;
}

.tile-sub {
  font-size: 14px;
  font-weight: 700;
  color: #aab0bd;
}

.tile:hover {
  transform: translateY(-2px);
  filter: brightness(1.18);
}

.tile:active {
  transform: translateY(0);
}

/* 編集モード中のタイル */
body.editing .tile {
  animation: wiggle 0.35s ease-in-out infinite alternate;
  border-style: dashed;
  touch-action: none; /* タッチでのドラッグ並べ替えを有効にする */
  user-select: none;
  -webkit-user-select: none;
}

.tile.dragging {
  position: fixed;
  animation: none !important;
  pointer-events: none;
  transform: scale(1.06);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.55);
  z-index: 1000;
}

.tile-placeholder {
  background: transparent;
  border: 2px dashed color-mix(in srgb, var(--text-dim) 60%, transparent);
  animation: none !important;
}

@keyframes wiggle {
  from { transform: rotate(-0.7deg); }
  to   { transform: rotate(0.7deg); }
}

/* 追加タイル */
.tile.add-tile {
  background: transparent;
  border: 2px dashed var(--border);
  color: var(--text-dim);
  font-size: 34px;
}

.tile.add-tile:hover {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: none;
}

body.editing .tile.add-tile {
  animation: none;
}

/* ===== ダイアログ ===== */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 10, 0.7);
  backdrop-filter: blur(6px);
  z-index: 100;
}

.overlay.hidden {
  display: none;
}

.dialog {
  width: min(420px, calc(100vw - 40px));
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.dialog h2 {
  font-size: 20px;
  margin-bottom: 20px;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field span {
  display: block;
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  color: var(--text);
  background: var(--tile);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s;
}

.field input:focus {
  border-color: var(--accent);
}

/* カラーピッカー */
.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: var(--swatch);
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s, border-color 0.15s;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.selected {
  border-color: var(--text);
  transform: scale(1.15);
}

.dialog-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

.spacer {
  flex: 1;
}

.btn {
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  border: none;
  border-radius: 12px;
  padding: 11px 20px;
  cursor: pointer;
  transition: filter 0.15s, background 0.2s;
}

.btn:hover {
  filter: brightness(1.15);
}

.btn-primary {
  background: var(--accent);
  color: #0d0f14;
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn-danger {
  background: transparent;
  color: #ff6c7d;
  border: 1px solid #ff6c7d;
}

.hidden {
  display: none !important;
}

/* スマホ */
@media (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
    padding: 16px 16px 80px;
  }

  .tile {
    min-height: 88px;
    padding: 14px 12px;
  }

  .tile-name {
    font-size: 16px;
  }
}
