@font-face { font-family: MyFont; src: url(/assets/League.otf) format("opentype"); }
*, :before, :after { box-sizing: border-box; }
html, body { background: #020617; min-height: 100%; margin: 0; color: #fff; font-family: Figtree, sans-serif; }
body { isolation: isolate; }
/* Background art on a fixed pseudo-element (background-attachment: fixed is broken on iOS),
   with the dimming layered in the same stack: vignette + top/bottom fade + overall tint. */
body::before {
  content: ""; position: fixed; inset: 0; height: 100vh; height: 100lvh; z-index: -1; pointer-events: none;
  background:
    radial-gradient(ellipse at center, rgba(2, 6, 23, 0) 35%, rgba(2, 6, 23, .75) 100%),
    linear-gradient(180deg, rgba(2, 6, 23, .55) 0%, rgba(2, 6, 23, .25) 40%, rgba(2, 6, 23, .7) 100%),
    linear-gradient(rgba(10, 14, 35, .35), rgba(10, 14, 35, .35)),
    url(/assets/background.jpg) center / cover no-repeat;
}
button { font-family: inherit; }

.home {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 40px 16px; color: #fff;
}
.titleCard {
  background: linear-gradient(135deg, #1f1f2e, #151521); border-radius: 20px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  margin-bottom: 14px; padding: 26px 40px; box-shadow: 0 12px 32px #00000073, inset 0 1px #ffffff0d;
  max-width: 100%; text-align: center;
}
.brand { letter-spacing: 1.6px; text-transform: uppercase; color: #b8b8ff; margin: 0; font-family: MyFont, sans-serif; font-size: 1.8rem; font-weight: 400; }
.title { color: #fff; margin: 0; font-size: 2.5rem; font-weight: 800; }
.timer { color: #cbd5f5; font-size: 1rem; }
.timer:empty { display: none; }

.nav { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; justify-content: center; }
.nav a, .nav button {
  color: #cbd5f5; text-decoration: none; background: #0f172acc; border: 1px solid #334155;
  border-radius: 999px; padding: 7px 16px; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.nav a.active { background: #2563eb; border-color: #2563eb; color: #fff; }
.nav .user { color: #a8c4f5; background: #0f172acc; border: 1px solid #3b82f6aa; border-radius: 999px; padding: 7px 14px; font-size: .9rem; font-weight: 600; }

.gameContainer {
  background: linear-gradient(145deg, #020617, #0f172a); border: 2px solid #0000; border-radius: 22px;
  padding: 22px 32px 32px; transition: border-color .3s; max-width: 100%;
}
.gameContainer.error { border-color: #ef4444; animation: 1s cubic-bezier(.36,.07,.19,.97) shake; }
.creator { text-align: center; color: #a1a1a1; margin: 0 0 3px; font-size: .95rem; }

.board { --row-height: calc((360px - (3*12px))/4); display: flex; flex-direction: column; gap: 12px; width: 520px; max-width: 100%; height: 360px; }
.solvedContainer { display: flex; flex-direction: column; gap: 10px; }
.solvedContainer:empty { display: none; }
.solvedRow { height: var(--row-height); border-radius: 10px; display: flex; justify-content: space-between; align-items: center; padding: 0 16px; gap: 10px; }
.solvedRow.animating { animation: .6s cubic-bezier(.34,1.56,.64,1) slideInBounce; }
.category { text-transform: uppercase; font-weight: 700; }
.category0 { background: #8f325f; } .category1 { background: #43835d; }
.category2 { background: #9b8f3f; } .category3 { background: #a03d3d; }
.words { opacity: .85; text-align: right; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: var(--row-height); flex: 1; gap: 12px; }
.tile {
  cursor: pointer; color: #fff; user-select: none; text-align: center; padding: 2px;
  text-shadow: -1px -1px #000, 1px -1px #000, -1px 1px #000, 1px 1px #000, 0 0 8px #000c;
  background-color: #1e4fa3; background-size: cover; background-position: center 20%;
  border: 1px solid #334155; border-radius: 10px; display: flex; justify-content: center; align-items: center;
  font-size: .9rem; font-weight: 700; transition: transform .15s;
}
.tile:hover { transform: translateY(-2px); }
.tile.fadeOut { animation: .4s ease-out forwards tileDissolve; }
.tile.selected { background-color: #3b82f6; box-shadow: 0 0 0 2px #9abbf3cc; filter: brightness(1.15); outline: 3px solid #3b82f6; outline-offset: -3px; }

.lives { display: flex; justify-content: center; align-items: center; margin-top: 22px; }
.livesLabel { margin-right: 8px; font-weight: 600; }
.buttonRow { display: flex; justify-content: center; gap: 16px; margin-top: 12px; flex-wrap: wrap; }
.actionButton { cursor: pointer; border: none; border-radius: 8px; padding: 12px 30px; font-size: 1rem; font-weight: 600; color: #fff; background: #475569; }
.actionButton:disabled { opacity: .4; cursor: not-allowed; }
.actionButton.submit { background: #2563eb; }
.actionButton.surrender { padding: 12px 22px; }
.actionButton.viewResult { background: #334155; padding: 10px 18px; font-size: .85rem; }
.actionButton.danger { background: #a03d3d; }

.modalOverlay { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 50; background: #020617d9; display: flex; justify-content: center; align-items: center; position: fixed; inset: 0; animation: .2s ease-out fadeIn; padding: 16px; }
.modal { text-align: center; color: #fff; background: linear-gradient(145deg, #0f172a, #020617); border-radius: 18px; width: 380px; max-width: 100%; padding: 32px; animation: .25s ease-out forwards popIn; transform: scale(.9); box-shadow: 0 30px 80px #0009; }
.modal.win { border: 2px solid #22c55e; } .modal.lose { border: 2px solid #ef4444; }
.modalIcon { margin-bottom: 12px; font-size: 3rem; }
.modalTitle { margin: 0; font-size: 1.8rem; font-weight: 800; }
.modalText { color: #cbd5f5; margin-top: 8px; }
.modalButtons { display: flex; gap: 12px; margin-top: 24px; }
.modalButton { cursor: pointer; color: #fff; background: #334155; border: none; border-radius: 10px; flex: 1; padding: 12px; font-size: .95rem; font-weight: 600; transition: background .15s, transform .15s; }
.modalButton:hover { background: #475569; transform: translateY(-1px); }
.modalButton.retry { background: #2563eb; } .modalButton.retry:hover { background: #1d4ed8; }

@keyframes popIn { to { transform: scale(1); } }
@keyframes fadeIn { 0% { opacity: 0; } }
@keyframes slideInBounce { 0% { opacity: 0; transform: translateY(-20px) scale(.95); } 60% { transform: translateY(5px) scale(1.02); } to { opacity: 1; transform: none; } }
@keyframes tileDissolve { 0% { opacity: 1; transform: scale(1); } 50% { transform: scale(1.05); } to { opacity: 0; transform: scale(.8); } }
@keyframes shake { 0%, to { transform: translate(0); } 10%,30%,50%,70%,90% { transform: translate(-2px); } 20%,40%,60%,80% { transform: translate(2px); } }

/* ---------- list ---------- */
.panel { width: 560px; max-width: 100%; }
.panelTitle { margin: 0 0 12px; font-size: 1.3rem; font-weight: 800; text-align: center; }
.filters { display: flex; gap: 6px; justify-content: center; margin-bottom: 14px; flex-wrap: wrap; }
.filters button { cursor: pointer; background: #1e293b; color: #cbd5f5; border: 1px solid #334155; border-radius: 8px; padding: 6px 12px; font-weight: 600; font-size: .85rem; }
.filters button.on { background: #2563eb; border-color: #2563eb; color: #fff; }
.gameList { display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 360px); min-height: 200px; overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
.gameCard { display: flex; gap: 12px; align-items: center; background: #1e293b66; border: 1px solid #334155; border-radius: 12px; padding: 10px 12px; cursor: pointer; transition: background .15s, transform .15s; color: #fff; text-decoration: none; }
.gameCard:hover { background: #1e293bcc; transform: translateY(-1px); }
.thumbs { display: grid; grid-template-columns: repeat(2, 26px); gap: 3px; flex: none; }
.thumbs span { width: 26px; height: 26px; border-radius: 5px; background: #1e4fa3 center/cover; }
.gameInfo { flex: 1; min-width: 0; }
.gameInfo b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gameMeta { color: #94a3b8; font-size: .82rem; margin-top: 2px; }
.badge { flex: none; font-size: .78rem; font-weight: 700; padding: 4px 8px; border-radius: 6px; background: #334155; color: #cbd5f5; }
.badge.won { background: #43835d; color: #fff; } .badge.lost { background: #a03d3d; color: #fff; }
.empty { text-align: center; color: #94a3b8; padding: 30px 0; }

/* ---------- forms / editor ---------- */
.formGroup { margin-bottom: 14px; }
.formGroup label { color: #cbd5f5; margin-bottom: 6px; font-size: .9rem; font-weight: 600; display: block; }
input { color: #fff; background: #1e293b; border: 2px solid #334155; border-radius: 6px; width: 100%; padding: 10px; font-size: .9rem; font-family: inherit; }
input:focus { outline: none; border-color: #2563eb; }
.group { background: #1e293b66; border-radius: 10px; margin-bottom: 12px; padding: 12px; border-left: 5px solid; }
.group h3 { color: #a8c4f5; margin: 0 0 8px; font-size: .95rem; }
.edWords { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
@media (min-width: 520px) { .edWords { grid-template-columns: repeat(4, 1fr); } }
.edWord { position: relative; }
.edWord input { padding-left: 38px; }
.edWord .pic { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 5px; background: #0f172a center/cover; border: 1px solid #334155; }
.formButtons { display: flex; gap: 10px; margin-top: 16px; }
.formButtons button { cursor: pointer; color: #fff; background: #334155; border: none; border-radius: 8px; flex: 1; padding: 11px; font-size: .95rem; font-weight: 600; }
.formButtons button.primary { background: #2563eb; }
.formButtons button.danger { background: #a03d3d; flex: 0 0 auto; padding: 11px 16px; }
.formButtons button:disabled { opacity: .6; cursor: not-allowed; }
.formError { color: #ef4444; text-align: center; margin-top: 10px; font-size: .9rem; min-height: 1em; }
.hint { color: #94a3b8; font-size: .82rem; margin: -4px 0 12px; text-align: center; }
.scroller { max-height: calc(100vh - 330px); overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
.authSwitch { text-align: center; margin-top: 14px; color: #94a3b8; font-size: .9rem; }
.authSwitch a { color: #a8c4f5; cursor: pointer; }
.results { margin-top: 16px; font-size: .85rem; color: #94a3b8; text-align: center; }
.results span { display: inline-block; margin: 2px 6px; }

@media (max-width: 768px) {
  .titleCard { padding: 18px 28px; }
  .brand { font-size: 1.4rem; } .title { font-size: 2rem; }
  .board { --row-height: calc((320px - (3*10px))/4); width: 420px; height: 320px; }
  .actionButton { padding: 10px 22px; font-size: .9rem; }
}
@media (max-width: 480px) {
  .home { padding-top: 20px; }
  .titleCard { width: 100%; padding: 14px 20px; }
  .brand { font-size: 1.1rem; } .title { font-size: 1.6rem; }
  .gameContainer { padding: 16px 14px 20px; }
  .board { --row-height: 60px; width: 100%; height: auto; }
  .grid { gap: 8px; }
  .tile { font-size: .72rem; }
  .solvedRow { padding: 0 10px; font-size: .72rem; }
  .actionButton { flex: 1; padding: 12px 10px; }
  .gameList, .scroller { max-height: none; }
}
@media (max-height: 800px) and (min-width: 481px) {
  .home { padding-top: 16px; padding-bottom: 16px; }
  .titleCard { gap: 4px; margin-bottom: 10px; padding: 12px 30px; }
  .brand { font-size: 1.3rem; } .title { font-size: 1.9rem; }
  .board { --row-height: calc((320px - (3*10px))/4); height: 320px; }
  .gameContainer { padding: 16px 28px 20px; }
  .lives { margin-top: 14px; }
}

/* ---------- polish & stats ---------- */
.clock { display: inline-block; margin-left: 10px; color: #94a3b8; font-variant-numeric: tabular-nums; font-size: .9em; }
.tile { position: relative; overflow: hidden; }
.tile::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, #0000 45%, #0009); pointer-events: none; }
.tile span { position: relative; z-index: 1; }
.tile.noimg { background: linear-gradient(145deg, #1e4fa3, #173c7c); }
.tile.noimg::after { display: none; }
.tile.selected::after { background: #3b82f659; }
.subActions { display: flex; justify-content: center; gap: 18px; margin-top: 14px; }
.subActions button, .subActions a { background: none; border: none; color: #94a3b8; font-size: .88rem; font-weight: 600; cursor: pointer; text-decoration: none; padding: 4px; }
.subActions button:hover, .subActions a:hover { color: #cbd5f5; }

.toast { position: fixed; top: 22px; left: 50%; transform: translateX(-50%); z-index: 100; background: #f8fafc; color: #020617; font-weight: 700; padding: 10px 20px; border-radius: 10px; box-shadow: 0 10px 30px #0008; animation: .2s ease-out fadeIn; transition: opacity .4s, transform .4s; }
.toast.out { opacity: 0; transform: translate(-50%, -10px); }

.modal.wide { width: 470px; position: relative; max-height: calc(100vh - 32px); overflow-y: auto; scrollbar-width: thin; }
.modal:not(.win):not(.lose) { border: 2px solid #334155; }
.modalClose { position: absolute; top: 10px; right: 14px; background: none; border: none; color: #94a3b8; font-size: 1.6rem; cursor: pointer; line-height: 1; }
.modalClose:hover { color: #fff; }
.modalText.small { font-size: .85rem; color: #94a3b8; }
.modalText a, .modal a { color: #a8c4f5; }
.statRow { display: flex; justify-content: center; gap: 12px; margin: 16px 0 14px; }
.statRow div { background: #1e293b; border-radius: 10px; padding: 10px 6px; flex: 1; display: flex; flex-direction: column; }
.statRow b { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.statRow span { font-size: .75rem; color: #94a3b8; text-transform: uppercase; letter-spacing: .5px; }
.eGrid { display: inline-flex; flex-direction: column; gap: 4px; margin: 4px auto; }
.eGrid div { display: flex; gap: 4px; }
.sq { width: 22px; height: 22px; border-radius: 5px; display: block; }
.eGrid.small { gap: 1px; margin: 0; } .eGrid.small div { gap: 1px; } .eGrid.small .sq { width: 6px; height: 6px; border-radius: 1.5px; }
.sq.c0 { background: #b5477d; } .sq.c1 { background: #4fa06f; } .sq.c2 { background: #c4b44d; } .sq.c3 { background: #c44c4c; }
.modalButtons { flex-wrap: wrap; }
.secTitle { text-align: left; margin: 22px 0 8px; font-size: .85rem; text-transform: uppercase; letter-spacing: .8px; color: #94a3b8; }
.dist { display: flex; flex-direction: column; gap: 4px; }
.bar { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.bar > span { width: 22px; text-align: right; color: #cbd5f5; font-weight: 700; }
.bar > div { flex: 1; }
.bar i { display: block; background: #334155; color: #fff; font-style: normal; font-weight: 700; text-align: right; padding: 2px 6px; border-radius: 4px; min-width: 22px; transition: width .6s ease-out; }
.bar.mine i { background: #2563eb; }
.lb { display: flex; flex-direction: column; gap: 4px; text-align: left; }
.lbRow { display: flex; align-items: center; gap: 10px; background: #1e293b80; border-radius: 8px; padding: 7px 10px; font-size: .9rem; }
.lbRow.me { background: #1e3a8a99; box-shadow: inset 0 0 0 1px #3b82f6; }
.lbRow .pos { width: 26px; text-align: center; font-weight: 700; }
.lbRow .nm { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lbRow .mi { color: #cbd5f5; width: 62px; text-align: right; }
.lbRow .tm { color: #94a3b8; width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: confettiFall linear forwards; }
@keyframes confettiFall { to { transform: translate(var(--dx), 105vh) rotate(var(--r)); opacity: .8; } }

.listTop { display: flex; gap: 8px; margin-bottom: 10px; }
.listTop button { cursor: pointer; background: #1e293b; border: 2px solid #334155; border-radius: 6px; font-size: 1.1rem; padding: 0 12px; transition: transform .15s; }
.listTop button:hover { transform: rotate(-12deg) scale(1.08); }

.topTable { display: flex; flex-direction: column; gap: 4px; max-height: calc(100vh - 330px); overflow-y: auto; scrollbar-width: thin; }
.topRow { display: grid; grid-template-columns: 34px 1fr 50px 56px 34px 48px 36px; gap: 6px; align-items: center; background: #1e293b80; border-radius: 8px; padding: 9px 10px; font-size: .9rem; text-align: center; }
.topRow .nm { text-align: left; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topRow.th { background: none; color: #94a3b8; font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; padding-top: 0; padding-bottom: 2px; }
.topRow.th span:nth-child(2) { text-align: left; }
.topRow.me { background: #1e3a8a99; box-shadow: inset 0 0 0 1px #3b82f6; }
@media (max-width: 480px) {
  .topRow { grid-template-columns: 26px 1fr 40px 46px 26px 40px 28px; font-size: .8rem; padding: 8px 6px; gap: 4px; }
  .modal.wide { padding: 24px 16px; }
  .lbRow .tm { display: none; }
}
.tile.locked { filter: grayscale(.85) brightness(.55); cursor: default; }
.tile.locked:hover { transform: none; }
.subActions { flex-wrap: wrap; gap: 6px 18px; }
