:root {
    color-scheme: light;
    --ink: #1c2430;
    --muted: #5c6b7a;
    --line: #e6ebf1;
    --danger: #c2413a;
    --ok: #0f7a4a;
    --tile: 108px;
    font-family: "Segoe UI", "Avenir Next", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
    color: var(--ink);
    min-height: 100vh;
}

.bg, .bg-shade {
    position: fixed;
    inset: 0;
    z-index: -2;
}

.bg {
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
}

.bg-shade {
    z-index: -1;
    background: linear-gradient(180deg, rgba(10, 16, 28, 0.5), rgba(10, 16, 28, 0.12) 26%, rgba(10, 16, 28, 0.32));
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    padding: 10px 16px;
    background: rgba(22, 28, 38, 0.55);
    backdrop-filter: blur(16px);
    color: #fff;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 750;
    text-decoration: none;
    letter-spacing: -0.02em;
}

.brand-mark {
    width: 22px;
    height: 22px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}

.brand-mark i {
    display: block;
    border-radius: 4px;
    background: #fff;
}

.brand-mark i:nth-child(1) { background: #7eb6ff; }
.brand-mark i:nth-child(2) { background: #ffb020; }
.brand-mark i:nth-child(3) { background: #3ddc97; }
.brand-mark i:nth-child(4) { background: #ff7a90; }

.pills {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 240px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.pill, .locale-form select, .user-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.16);
    cursor: pointer;
}

.pill.is-active, .pill-strong {
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(66, 133, 244, 0.9);
}

.pill-add, .pill-icon {
    width: 36px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
}

.pill-icon svg { width: 18px; height: 18px; }

.pill-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #12b886;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.locale-form select {
    padding-right: 28px;
    background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
    background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    appearance: none;
}

.user-chip { max-width: 240px; }

.user-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.avatar, .badge {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #2457c5;
    color: #fff;
    font-size: 12px;
}

.badge {
    width: auto;
    padding: 0 8px;
    border-radius: 999px;
    background: #12315f;
    font-size: 11px;
}

.main { padding: 18px 16px 64px; }

.shared-note, .toast {
    width: min(1120px, 100%);
    margin: 0 auto 12px;
    color: #fff;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    z-index: 25;
    width: auto;
    margin: 0;
    padding: 10px 16px;
    border-radius: 999px;
    background: rgba(20, 28, 38, 0.88);
    transform: translateX(-50%);
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(720px, 100%);
    margin: 8px auto 22px;
}

.web-search {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    padding: 4px 4px 4px 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.web-search input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    border: 0;
    background: transparent;
    padding: 10px 12px 10px 16px;
    font: inherit;
    font-size: 16px;
    outline: none;
}

.web-search button {
    flex: 0 0 auto;
    border: 0;
    border-radius: 999px;
    padding: 0 16px;
    background: #2457c5;
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.search-engine {
    flex: 0 0 auto;
    width: max-content;
    max-width: 6.75rem;
    margin: 0;
    padding: 3px 14px 3px 7px;
    border: 0;
    border-radius: 999px;
    background-color: rgba(255, 255, 255, 0.94);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
}

.board {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns, 9), minmax(0, 1fr));
    grid-template-rows: repeat(var(--grid-rows, 6), auto);
    gap: 8px;
    width: min(1080px, 100%);
    margin: 0 auto;
}

.slot { min-width: 0; position: relative; }

.slot-1 { aspect-ratio: 1; }

.slot-2 .tile-face { height: 100%; aspect-ratio: auto; }

.tile-face {
    container-type: inline-size;
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    aspect-ratio: 1;
    border: 0;
    border-radius: 18px;
    overflow: hidden;
    background: var(--tile-color, #4c6ef5);
    box-shadow: 0 12px 22px rgba(0, 0, 0, 0.28), inset 0 0 0 1px rgba(255, 255, 255, 0.38);
    color: #fff;
    font: inherit;
    cursor: pointer;
}

.tile-hit {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    color: inherit;
    text-decoration: none;
}

.tile-face img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    padding: 12%;
    background: transparent;
}

.tile-letter {
    color: #fff;
    font-size: 42cqw;
    font-weight: 800;
    line-height: 1;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.tile-caption {
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 6px;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

.slot-empty .tile-face {
    min-width: 0;
    background: rgba(72, 80, 92, 0.28);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
    opacity: 0.42;
    cursor: default;
}

.slot-empty button.tile-face { cursor: pointer; }

.slot-empty:hover .tile-face {
    opacity: 0.72;
    background: rgba(88, 98, 112, 0.4);
}

.slot-label {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 8px;
    opacity: 0;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    pointer-events: none;
}

.slot-empty:hover .slot-label {
    opacity: 1;
}

.board[data-move-url] .slot[data-tile-id],
.board[data-move-url] .slot[data-tile-id] .tile-hit,
.board[data-move-url] .slot[data-tile-id] img {
    -webkit-user-drag: none;
    user-select: none;
    touch-action: none;
}

.board[data-move-url] .slot[data-tile-id] .tile-face,
.board[data-move-url] .slot[data-tile-id] .tile-hit {
    cursor: grab;
}

.slot.is-dragging { opacity: 0.35; }

.board.is-sorting,
.board.is-sorting .tile-face,
.board.is-sorting .tile-hit {
    cursor: grabbing;
}

.drag-ghost {
    position: fixed;
    z-index: 50;
    margin: 0;
    pointer-events: none;
    transform: translate(-50%, -120%);
    opacity: 0.92;
    cursor: grabbing;
    filter: drop-shadow(0 16px 24px rgba(0, 0, 0, 0.35));
}

.board.is-sorting .slot-empty .slot-label {
    opacity: 0;
}

.board.is-sorting .slot-empty.is-drop .tile-face {
    opacity: 0.88;
    background: rgba(186, 198, 214, 0.55);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.8);
}

.tile-add {
    color: #fff;
    font-size: 42px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.16);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7);
}

.tile-edit {
    position: absolute;
    top: 8px;
    right: 8px;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--ink);
    cursor: pointer;
    opacity: 0;
}

.tile-edit svg { width: 16px; height: 16px; }

.slot:hover .tile-edit,
.slot:focus-within .tile-edit,
.tile-edit:focus { opacity: 1; }

.menu {
    position: fixed;
    z-index: 60;
    min-width: 220px;
    padding: 8px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

.menu-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 10px;
    border-bottom: 1px solid var(--line);
}

.menu-thumb, .menu-thumb img {
    width: 42px;
    height: 42px;
    border-radius: 12px;
}

.menu-thumb {
    display: grid;
    place-items: center;
    overflow: hidden;
    color: #fff;
    font-weight: 800;
    flex: 0 0 auto;
}

.menu-thumb img {
    object-fit: contain;
    padding: 4px;
    background: transparent;
}

.menu-head strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu button {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 10px 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.menu button:hover,
.menu button:focus { background: #f3f6fa; }

.menu button:disabled {
    color: #9aa6b2;
    cursor: not-allowed;
}

.backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(8, 12, 20, 0.35);
}

.drawer {
    position: fixed;
    z-index: 40;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(390px, 100%);
    overflow: auto;
    padding: 18px 18px 32px;
    background: #fff;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.25);
}

.drawer-head, .account-links {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.drawer h2, .card h1, .card h2 { margin: 0 0 12px; }

.icon-button {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: #f2f5f8;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.card {
    width: min(440px, calc(100% - 8px));
    margin: 28px auto;
    padding: 28px 24px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.card-wide { width: min(760px, calc(100% - 8px)); }

.about-points {
    display: grid;
    gap: 14px;
    margin: 22px 0 0;
    padding: 0;
    list-style: none;
}

.about-points li {
    padding: 14px 16px;
    border-radius: 16px;
    background: #f4f7fb;
}

.about-points h2 { margin: 0 0 4px; font-size: 18px; }

.about-actions { display: flex; gap: 10px; margin-top: 22px; }

.lede, .help, .switch-auth, .manual-key { color: var(--muted); }

.stack {
    margin-top: 22px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

label, .field-label { display: block; margin: 14px 0 6px; font-weight: 700; }

input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="search"], select, textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px 12px;
    border: 1px solid #d5dee8;
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-size: 16px;
}

.search-bar .web-search input,
.search-bar .search-engine {
    display: block;
    margin: 0;
    border: 0;
}

.search-bar .web-search input {
    width: 100%;
}

.search-bar .search-engine {
    width: max-content;
    max-width: 6.75rem;
    padding: 3px 14px 3px 7px;
    font-size: 12px;
}

input:focus, select:focus, button:focus-visible, a:focus-visible {
    outline: 3px solid rgba(36, 87, 197, 0.45);
    outline-offset: 2px;
}

.check, .choice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-weight: 650;
}

.check input, .choice input { margin-top: 3px; }

.check small, .check strong { display: block; }

.check small { color: var(--muted); font-weight: 500; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    margin-top: 14px;
    padding: 0 16px;
    border: 0;
    border-radius: 12px;
    background: #2457c5;
    color: #fff;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
    text-decoration: none;
}

.button-danger { background: var(--danger); }

.button-quiet {
    background: #eef3f8;
    color: var(--ink);
}

.alert {
    margin: 12px 0;
    padding: 10px 12px;
    border-radius: 12px;
    background: #fff1f0;
    color: #8d221c;
}

.alert p { margin: 0; }

.alert-ok { background: #e8f8ef; color: var(--ok); }

.dropzone {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 140px;
    margin-top: 6px;
    padding: 12px;
    border: 2px dashed #b7c4d2;
    border-radius: 16px;
    background: #f7fafc;
    text-align: center;
    color: var(--muted);
    font-weight: 650;
    overflow: hidden;
}

.dropzone.is-dragover { border-color: #2457c5; background: #eef4ff; }

.dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.dropzone img {
    width: 100%;
    max-height: 160px;
    object-fit: contain;
    border-radius: 12px;
}

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }

.swatch {
    width: 28px;
    height: 28px;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px #d0d7e0;
    cursor: pointer;
}

.color-field input[type="color"] {
    width: 64px;
    height: 40px;
    margin-top: 10px;
    padding: 0;
    border: 0;
    background: transparent;
}

.qr { display: block; width: 200px; height: 200px; margin: 8px 0; background: #fff; }

.recovery ul {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 0;
    list-style: none;
}

.recovery code, .manual-key code {
    font-size: 15px;
}

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th, td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.account-links { margin-top: 24px; }

@media (hover: none) {
    .tile-edit { opacity: 1; }
}

@media (max-width: 720px) {
    :root { --tile: 92px; }
    .pills { order: 3; flex-basis: 100%; }
    .badge { display: none; }
    .user-chip { max-width: 46vw; padding: 0 10px; }
    .drawer { width: 100%; }
    .recovery ul { grid-template-columns: 1fr; }
    .card { margin-top: 12px; padding: 20px 16px; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto; }
}
