:root { --ts: 72px; --gap: 6px; --bg: #0f1115; --fg: #e8eaee; --muted: #8b93a3; --panel: #1a1d24; --accent: #2f9a73; color-scheme: dark; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg) center / cover fixed; color: var(--fg); font: 14px/1.4 system-ui, sans-serif; min-height: 100vh; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid #333a47; border-radius: 6px; padding: 6px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: #ff8a80; }
input, select { background: #12151b; border: 1px solid #333a47; border-radius: 6px; padding: 6px 8px; width: 100%; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 0; height: 32px; }

#top { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: #0b0d11cc; position: sticky; top: 0; z-index: 5; backdrop-filter: blur(6px); }
#tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: thin; }
.tab { flex: none; border-radius: 8px 8px 0 0; border: 0; border-bottom: 3px solid var(--tabc, var(--accent)); background: #1a1d24; white-space: nowrap; }
.tab.active { background: var(--tabc, var(--accent)); color: #fff; }
.tab.hidden-mix { opacity: .45; }
body.dragging-tile .tab { outline: 2px dashed var(--accent); }
.tab.drop-over { background: #2c3a33; }
#bar { display: flex; gap: 6px; align-items: center; flex: none; }
#status { color: var(--muted); font-size: 12px; min-width: 70px; text-align: right; }
#status.err { color: #ff8a80; }
body.editing #btn-edit { background: var(--accent); border-color: var(--accent); }
#banner { background: #5a3a12; padding: 8px 12px; text-align: center; }
#banner button { margin-left: 8px; }

#stage { padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
#search { width: min(560px, 100%); background: #14171dcc; border-radius: 10px; padding: 10px; display: grid; gap: 8px; }
#search .row { display: flex; gap: 6px; }
#engines, #modes { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; }
#engines button, #modes button { padding: 2px 8px; border-radius: 12px; }
#engines .on, #modes .on { background: var(--accent); border-color: var(--accent); color: #fff; }

#grid { display: grid; gap: var(--gap); justify-content: center; max-width: 100%; }
.cell { min-width: 0; min-height: 0; border-radius: 8px; }
body.editing .cell.empty { background: #ffffff0d; outline: 1px dashed #ffffff22; cursor: pointer; }
.cell .tile, .cell .embed { width: 100%; height: 100%; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px; border-radius: 8px; color: #fff; text-decoration: none; background: var(--tc, #3a3f4b); overflow: hidden; text-align: center; position: relative; }
.tile:focus-visible { outline: 3px solid #fff; }
.tile .ic { font-size: calc(var(--ts) * .42); line-height: 1; max-width: 80%; }
.tile img.ic { width: calc(var(--ts) * .5); height: calc(var(--ts) * .5); object-fit: contain; }
.tile .nm { font-size: 11px; line-height: 1.1; max-height: 2.4em; overflow: hidden; word-break: break-word; }
.tile .ds { font-size: 10px; opacity: .85; display: none; }
.tile:hover .ds { display: block; }
body.editing .tile { cursor: grab; }
.embed { background: #1a1d24; border-radius: 8px; padding: 8px; overflow: auto; position: relative; }
.embed textarea { width: 100%; height: 100%; resize: none; background: transparent; border: 0; color: inherit; }
.embed .clock { font-size: 28px; text-align: center; }
.embed ul { margin: 0; padding-left: 16px; font-size: 12px; }
.embed a { color: #8fd3b6; }
.embed .edit { position: absolute; top: 2px; right: 2px; font-size: 11px; padding: 0 6px; display: none; }
body.editing .embed .edit { display: block; }
.sortable-ghost { opacity: .4; }

dialog { background: var(--panel); color: var(--fg); border: 1px solid #333a47; border-radius: 12px; width: min(460px, 94vw); padding: 16px; }
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog label { display: grid; gap: 3px; margin: 8px 0; }
.chk { display: flex !important; align-items: center; gap: 6px; white-space: nowrap; }
.inline { display: flex; gap: 6px; align-items: center; }
menu { display: flex; gap: 6px; justify-content: flex-end; padding: 0; margin: 14px 0 0; }
.size { display: flex; gap: 6px; align-items: center; margin: 8px 0; }
.chooser { display: flex; gap: 6px; flex-wrap: wrap; }
.chooser button { padding: 2px; }
.chooser img { width: 32px; height: 32px; object-fit: contain; display: block; }
.hint { color: var(--muted); font-size: 12px; }
.filebtn { border: 1px solid #333a47; border-radius: 6px; padding: 6px 10px; cursor: pointer; margin: 0; }

@media (max-width: 600px) {
  :root { --ts: calc((100vw - 24px - 3 * var(--gap)) / 4); }
  #top { flex-wrap: wrap; }
  #bar { width: 100%; justify-content: flex-end; }
  dialog { position: fixed; inset: auto 0 0 0; width: 100%; max-width: none; margin: 0; border-radius: 16px 16px 0 0; max-height: 88vh; overflow: auto; }
  .tile .nm { font-size: 10px; }
}
