:root {
  --bg: #0f0f14;
  --panel: #1a1a22;
  --border: #2b2b36;
  --text: #eee;
  --muted: #999;
  --accent: #6c5ce7;
  --danger: #e74c3c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

header h1 { margin: 0; font-size: 20px; }

.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: transform 0.1s, background 0.2s;
  touch-action: manipulation;
}

.btn.small { padding: 6px 10px; font-size: 12px; }
.btn:hover { background: #24242f; }
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: #5a4bd6; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #c0392b; }
.btn.hidden { display: none; }

.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  padding: 20px;
}

@media (min-width: 700px) {
  .board { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; padding: 24px 30px; }
}

.tile {
  position: relative;
  border-radius: 14px;
  min-height: 110px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.sound-btn {
  position: relative;
  border: none;
  border-radius: 14px;
  padding: 22px 12px 14px;
  width: 100%;
  height: 100%;
  min-height: 110px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.08s ease;
  text-align: center;
}

.sound-btn:hover { transform: translateY(-3px); }
.sound-btn.playing { outline: 3px solid #fff; }
.sound-btn:active { transform: scale(0.96); }

.sound-btn .desc {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.85;
  line-height: 1.3;
}

.sound-btn .placeholder-tag {
  font-size: 11px;
  opacity: 0.75;
  font-weight: 400;
}

.key-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.4);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: #fff;
}

.gear-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.4);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  z-index: 2;
  touch-action: manipulation;
}

.gear-btn:hover { background: rgba(0,0,0,0.6); }

.tile.dragging { opacity: 0.4; }
.tile.drag-over { outline: 2px dashed var(--accent); outline-offset: 3px; }

.add-tile {
  border: 2px dashed var(--border);
  border-radius: 14px;
  min-height: 110px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  touch-action: manipulation;
}

.add-tile:hover { border-color: var(--accent); color: var(--text); }
.add-tile .plus { font-size: 26px; line-height: 1; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 { margin-top: 0; }

.modal-content label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}

.modal-content .optional { font-size: 11px; opacity: 0.7; }

.modal-content input[type="text"],
.modal-content input[type="file"] {
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #101015;
  color: var(--text);
  font-size: 14px;
}

.modal-content input[type="color"] {
  margin-top: 6px;
  width: 60px;
  height: 32px;
  border: none;
  background: none;
}

.hotkey-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.hotkey-input-row .key {
  background: #101015;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  min-width: 60px;
  text-align: center;
}

.hotkey-input-row .key.listening { background: var(--accent); color: #fff; }

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.modal-actions-right { display: flex; gap: 10px; }

.status { font-size: 13px; color: var(--muted); min-height: 18px; }

.hint { font-size: 13px; color: var(--muted); margin-top: 0; }

.hotkey-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.hotkey-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 8px;
}

.hotkey-row .name {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hotkey-row .row-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

input[type="range"] {
  width: 100%;
  margin-top: 8px;
  accent-color: var(--accent);
}

@media (max-width: 480px) {
  header h1 { font-size: 17px; }
  .btn { padding: 8px 12px; font-size: 13px; }
}