/* ---- Fælles udseende (bruger temaernes variabler) + spillayout, HUD og effekter ---- */
body { background: var(--page); background-attachment: fixed; color: var(--page-ink); font-family: var(--font-body); }
h1, h2, h3, .code, .turn-title, .modal h2 { font-family: var(--font-head); letter-spacing: .01em; }
.panel, .modal { border-radius: var(--radius); }
.panel { background: var(--panel); color: var(--ink); }
.modal, .turn:not(.mine):not(.won):not(.lost), .theme-opt { color: var(--ink); }
.btn { border-radius: calc(var(--radius) * .7); background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.alt { background: transparent; color: var(--ink); border: 1px solid color-mix(in srgb, var(--ink) 40%, transparent); }
input.txt, select.txt { background: var(--input-bg); color: var(--input-ink); border-color: color-mix(in srgb, var(--ink) 25%, transparent); border-radius: calc(var(--radius) * .7); }
.item { background: var(--item); border-radius: calc(var(--radius) * .7); }
.item.mine { background: var(--item-strong); box-shadow: inset 4px 0 0 var(--hit); }
.tag { background: color-mix(in srgb, var(--ink) 12%, transparent); }
.tag.turn { background: var(--hit); color: #fff; }
.modal .stats div { background: var(--item); }
.muted { color: var(--muted); }
#toast { background: var(--accent); color: var(--accent-ink); }
.board { background: var(--water); border-radius: calc(var(--radius) * .8); box-shadow: 0 2px 10px #0003; }
.cell { border-color: var(--water-line); }
.mark.hit::after { color: var(--hit); }
.mark.miss::after { background: var(--miss); }

/* skibe = SVG */
.ship { background: none; border: 0; box-shadow: none; border-radius: 0; }
.ship svg { width: 100%; height: 100%; display: block; overflow: visible; filter: drop-shadow(0 2px 2px #0005); }
.ship.enemy { opacity: .8; }
.ship.sunk svg { filter: grayscale(.55) brightness(.7) sepia(.4) hue-rotate(-25deg) drop-shadow(0 2px 2px #0005); }
.place .ship.bad svg { filter: drop-shadow(0 0 5px var(--warn)) saturate(2) hue-rotate(-30deg); }
.place .ship.drag { filter: drop-shadow(0 6px 8px #0006); }
:root[data-theme="radar"] .ship svg { filter: drop-shadow(0 0 5px #4dff88aa); }
:root[data-theme="radar"] .board::before { content: ""; position: absolute; inset: -50%; z-index: 0; pointer-events: none;
  background: conic-gradient(from 0deg, transparent 0 82%, #4dff8840 100%); animation: sweep 5s linear infinite; }
@keyframes sweep { to { transform: rotate(360deg); } }
:root[data-theme="blueprint"] .ship svg { filter: none; }

/* eksplosion og plop (korte, ikke-blokerende) */
.cell.fresh { z-index: 6; }
.fx { position: absolute; left: 50%; top: 50%; pointer-events: none; }
.boom { width: 100%; height: 100%; margin: -50% 0 0 -50%; border-radius: 50%;
  background: radial-gradient(circle, #fff 0, #ffe27a 28%, #ff8a1f 52%, #e5484d00 72%); animation: boom .45s ease-out forwards; }
.spark { width: 13%; height: 13%; margin: -6.5% 0 0 -6.5%; border-radius: 50%; background: #ffc233;
  transform: rotate(var(--a)); animation: spark .42s ease-out forwards; }
.ripple { width: 100%; height: 100%; margin: -50% 0 0 -50%; border: 2px solid var(--miss); border-radius: 50%; opacity: 0;
  animation: ripple .5s ease-out forwards; }
.ripple.r2 { animation-delay: .1s; }
.drop { width: 22%; height: 22%; margin: -11% 0 0 -11%; border-radius: 50%; background: var(--miss); animation: drop .3s ease-in forwards; }
@keyframes boom { from { transform: scale(.15); opacity: 1; } to { transform: scale(2.7); opacity: 0; } }
@keyframes spark { to { transform: rotate(var(--a)) translateX(6.5cqw) scale(.2); opacity: 0; } }
@keyframes ripple { from { transform: scale(.2); opacity: .95; } to { transform: scale(2.1); opacity: 0; } }
@keyframes drop { from { transform: translateY(-110%) scale(1.3); opacity: 1; } to { transform: translateY(0) scale(.5); opacity: 0; } }
.board.shake { animation: shake .25s; }
@keyframes shake { 25% { transform: translate(-2px, 1px); } 50% { transform: translate(2px, -1px); } 75% { transform: translate(-1px, 1px); } }
@media (prefers-reduced-motion: reduce) { .fx, .board::before { display: none !important; } .mark.new::after { animation: none; } }

/* ---- spilskærm (mobil først) ---- */
body.in-game #top { display: none; }
body.in-game main { max-width: none; padding: 0 0 14px; }
.game { display: grid; gap: 10px; align-items: start; grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "head head" "enemy enemy" "own hud"; }
.game:not(.live) { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "enemy" "own" "hud"; }
.ghead { grid-area: head; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px 2px; }
.ghead .hl { display: flex; align-items: center; gap: 10px; min-width: 0; }
.oppname { font-family: var(--font-head); font-weight: 700; font-size: 1.2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn.turn-d, .plabel { display: none; }
.area-enemy { grid-area: enemy; min-width: 0; }
.area-own { grid-area: own; min-width: 0; margin-top: 12px; padding-left: 12px; }
.hud { grid-area: hud; min-width: 0; padding: 12px 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.game:not(.live) .area-own, .game:not(.live) .hud { padding: 0 12px; margin-top: 0; }
.area-enemy .board { width: min(100vw, max(260px, calc(100dvh - 330px))); margin: 0 auto; border-radius: 0; }
.game:not(.live) .area-enemy .board { width: min(100vw, 480px); }
.game:not(.live) .area-enemy > .panel { margin: 0 12px; }
.game.live .area-own .board { width: 150px; }
.area-enemy.myturn .board { box-shadow: 0 0 0 3px var(--accent-glow), 0 0 26px color-mix(in srgb, var(--accent-glow) 70%, transparent); }
.claim { padding: 10px; }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; font-size: 1rem; flex: none; box-shadow: 0 1px 3px #0004; }
.me { display: flex; align-items: center; gap: 8px; font-size: .9rem; min-width: 0; }
.me .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score { display: inline-flex; align-items: center; gap: 4px; color: var(--page-muted); font-weight: 600; }
.score .ico { width: 16px; height: 16px; }

.turn { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: calc(var(--radius) * .8);
  background: var(--panel); box-shadow: 0 1px 4px #0003; border: 0; text-align: left; width: 100%; font: inherit; }
.turn.mine { background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 2px var(--accent-glow), 0 4px 18px color-mix(in srgb, var(--accent-glow) 55%, transparent); }
.turn.mine .turn-ico { background: #ffffff26; animation: pulse 1.4s ease-in-out infinite; }
.turn.won { background: var(--good); color: #fff; } .turn.lost { background: var(--hit); color: #fff; }
.turn-ico { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--ink) 12%, transparent); }
.turn-title { font-family: var(--font-head); font-size: 1.15rem; line-height: 1.1; font-weight: 700; }
.turn-sub { font-size: .78rem; opacity: .8; margin-top: 2px; }
@keyframes pulse { 50% { transform: scale(1.12); } }

.tools { display: flex; gap: 6px; }
.tool { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; border: 0; background: color-mix(in srgb, var(--page-ink) 14%, transparent); color: var(--page-ink); padding: 0; }
.tool:hover { background: color-mix(in srgb, var(--page-ink) 26%, transparent); }
.ico { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* indstillinger */
.modal.settings { text-align: left; max-height: 92dvh; overflow: auto; }
.modal.settings h2 { text-align: center; margin: 0 0 6px; }
.set-h { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--muted); margin: 14px 0 6px; }
.segs { display: flex; gap: 8px; }
.seg { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; min-height: 44px; border-radius: 12px; border: 2px solid transparent; background: var(--item); color: var(--ink); font: inherit; font-weight: 600; }
.seg.cur { border-color: var(--accent-glow); background: var(--item-strong); }
.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; border: 2px solid transparent; background: var(--item); color: var(--ink); font: inherit; font-weight: 600; }
.theme-opt.cur { border-color: var(--accent-glow); background: var(--item-strong); }
.swatch { display: flex; } .swatch i { width: 14px; height: 24px; display: block; } .swatch i:first-child { border-radius: 7px 0 0 7px; } .swatch i:last-child { border-radius: 0 7px 7px 0; }

/* lobby-topbar */
.link { color: var(--page-ink); }
#top .who { gap: 8px; color: var(--page-ink); }
#top .tool { width: 34px; height: 34px; }

/* ---- bred skærm: de to 10x10-brætter fylder skærmen ---- */
@media (min-width: 761px) {
  body.in-game main { padding: 8px 12px 10px; }
  .game, .game.live, .game:not(.live) { grid-template-columns: 1fr 1fr; gap: 8px 24px; grid-template-areas: "head head" "enemy own" "hud hud"; }
  .ghead { display: grid; grid-template-columns: 1fr auto 1fr; padding: 0; }
  .ghead .hl { visibility: hidden; }
  .ghead .tools { justify-self: end; }
  .turn.turn-d { display: flex; width: auto; min-width: 300px; padding: 6px 14px; }
  .turn.turn-m, .hud .me { display: none; }
  .hud { padding: 0; }
  .area-own, .game:not(.live) .area-own { padding: 0; margin: 0; }
  .plabel { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 6px; font-family: var(--font-head); font-weight: 700; font-size: 1.1rem; color: var(--page-ink); }
  .plabel .avatar { width: 28px; height: 28px; font-size: .9rem; }
  .area-enemy .board, .game.live .area-own .board, .game:not(.live) .area-enemy .board { width: min(100%, calc(100dvh - 138px)); border-radius: calc(var(--radius) * .8); }
  .game:not(.live) .area-own .board { width: min(100%, 480px); }
  .game:not(.live) .area-enemy > .panel { margin: 0; }
  .turn-title { font-size: 1.3rem; }
}

.game .board { max-width: none; }
.plabel .score { font-family: var(--font-body); font-size: .85rem; }

/* luft: mindre bræt, større mellemrum */
.oppname, .pname { letter-spacing: .04em; font-size: 1rem; }
@media (max-width: 760px) {
  body.in-game main { padding: 0 0 24px; }
  .game { gap: 18px; }
  .ghead { padding: 14px 16px 0; }
  .area-enemy { padding: 0 14px; }
  .area-enemy .board { width: min(100%, max(240px, calc(100dvh - 380px))); border-radius: calc(var(--radius) * .8); }
  .game:not(.live) .area-enemy .board { width: min(100%, 440px); }
  .area-own { margin-top: 0; padding-left: 14px; }
  .hud { padding: 0 14px 0 0; gap: 14px; }
  .game:not(.live) .area-own, .game:not(.live) .hud { padding: 0 14px; }
  .game:not(.live) .area-enemy > .panel { margin: 0; }
}
@media (min-width: 761px) {
  body.in-game main { padding: 18px 28px 26px; }
  .game, .game.live, .game:not(.live) { gap: 16px 56px; }
  .area-enemy .board, .game.live .area-own .board, .game:not(.live) .area-enemy .board { width: min(100%, calc(100dvh - 190px)); }
}

/* desktop: modstander 3/6 · status 1/6 · eget bræt 2/6 */
.turn.turn-mid { display: none; }
@media (min-width: 761px) {
  .game, .game.live, .game:not(.live) { grid-template-columns: 3fr 1fr 2fr; gap: 16px 28px; grid-template-areas: "head head head" "enemy mid own" "hud hud hud"; }
  .ghead { display: flex; justify-content: flex-end; padding: 0; }
  .ghead .hl { display: none; }
  .turn.turn-mid { grid-area: mid; display: flex; flex-direction: column; align-self: center; text-align: center; width: auto; padding: 18px 10px; gap: 8px; }
  .turn-mid .turn-ico { width: 44px; height: 44px; }
  .turn-mid .turn-title { font-size: 1.25rem; }
  .area-own { align-self: start; }
}

/* invitations-popup */
.modal.invite { text-align: center; }
.modal.invite .big { font-size: 2.6rem; margin-bottom: 4px; }
.modal.invite .avatar.xl { width: 64px; height: 64px; font-size: 1.8rem; margin: 6px auto; }
.modal.invite h2 { margin: 8px 0 4px; }
.modal.invite .modal-actions { margin-top: 18px; }
#invite-modal { z-index: 40; }

/* avatarbilleder + profil */
.avatar.img { background: var(--item-strong); overflow: hidden; padding: 0; }
.avatar.img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.xl { width: 72px; height: 72px; font-size: 2rem; }
.prof { display: flex; gap: 14px; align-items: center; }
.prof-edit { flex: 1; min-width: 0; }
.prof-edit .txt { min-height: 40px; }

/* mobil: kortet man skyder på fylder næsten hele bredden */
@media (max-width: 760px) {
  .area-enemy { padding: 0 6px; }
  .area-enemy .board { width: 100%; }
  .game:not(.live) .area-enemy .board { width: min(100%, 440px); }
}

/* beskæring af avatar */
.modal.crop { text-align: center; }
.cropper { position: relative; margin: 14px auto 8px; border-radius: 12px; overflow: hidden; touch-action: none; cursor: grab; background: #000; }
.cropper:active { cursor: grabbing; }
.cropper canvas { display: block; }
.crop-mask { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(circle at center, transparent 0 69%, #000a 70%); box-shadow: inset 0 0 0 2px #fff6; }
.crop-mask::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid #fff; box-sizing: border-box; }
.zoom-row { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; }
.zoom { flex: 1; accent-color: var(--accent-glow); height: 28px; }

/* indstillinger: kompakt, uden scroll */
.modal.settings { padding: 18px 18px 16px; }
.prof-avatar { position: relative; flex: none; }
.av-x { position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--panel); background: var(--hit); color: #fff; font-size: .75rem; line-height: 1; display: grid; place-items: center; padding: 0; cursor: pointer; }
.modal.settings .seg { min-height: 40px; padding: 6px; }
.modal.settings .theme-opt { padding: 6px 10px; }

.rematch-note { font-family: var(--font-head); font-size: 1.1rem; font-weight: 700; padding: 4px 0; }

/* ingen dobbelttryk-zoom (iOS) og ingen tekstskalering ved drejning */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body, button, input, select, a, .cell, .board { touch-action: manipulation; }
.board.place, .place .ship, .cropper { touch-action: none; }
input, select, textarea { font-size: 16px; }
