/* Layout: one column on a phone (opponent, board, you, message, buttons, move list),
   on a wide screen the board on the left and the game panel on the right. Style and colours from the AleGry.pl 2.0 mockup,
   as in Stworek: a single light "paper" look, thick outlines and hard shadows. */
:root {
  --paper: #FFF7EA;
  --paper-2: #FBEBD3;
  --ink: #1D1533;
  --text-2: #574D6E;
  --card: #FFFFFF;
  --tomato: #FF5A3C;
  --tomato-dark: #C93A20;
  --tomato-light: #FFE1D9;
  --lemon: #FFD23F;
  --lemon-light: #FFF3C4;
  --mint: #20B69A;
  --mint-light: #D3F4EC;
  --plum: #7A5CFA;
  --plum-light: #E9E3FF;
  --sky: #3DB8EC;
  --sky-light: #DAF1FC;
  --night: #2A2148;
  --square-light: #FFF3C4;
  --square-dark: #5FC7B2;
  --trail: rgba(255, 210, 63, .62);
  --selection: rgba(122, 92, 250, .42);
  --dot: rgba(29, 21, 51, .28);
  --stroke: 3px solid var(--ink);
  --shadow: 5px 5px 0 var(--ink);
  --shadow-small: 3px 3px 0 var(--ink);
  --r: 18px;
  --r-small: 10px;
  --font-display: 'Fredoka', 'Trebuchet MS', sans-serif;
  --font-text: 'Nunito', 'Segoe UI', Verdana, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { background: var(--paper); color: var(--ink); }
body {
  margin: 0;
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px 24px;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--plum); outline-offset: 3px; border-radius: 6px; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; margin: 0; font-weight: 700; text-wrap: balance; }

.app { max-width: 1020px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ---------- Header ---------- */
.bar { display: flex; align-items: center; gap: 10px; }
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); margin-right: auto; min-width: 0; }
.logo svg { flex: none; width: 38px; height: 38px; }
.logo-text { font: 700 24px/1 var(--font-display); letter-spacing: -0.03em; }
.logo-text b { color: var(--tomato); }
.logo small { display: block; font: 800 12px/1.2 var(--font-text); color: var(--text-2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font: 700 17px/1 var(--font-display);
  background: var(--card); border: var(--stroke); border-radius: 999px; padding: 7px 12px; box-shadow: var(--shadow-small);
  font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink);
}
.chip-trophy { background: var(--lemon); }
button.chip { cursor: pointer; }
button.chip:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
.btn-icon {
  width: 42px; height: 42px; display: inline-grid; place-items: center; flex: none; cursor: pointer;
  background: var(--card); border: var(--stroke); border-radius: 50%; box-shadow: var(--shadow-small); font-size: 19px; padding: 0;
}
.btn-icon:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
@media (max-width: 420px) { .chip-level .label { display: none; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 700 17px/1 var(--font-display);
  background: var(--tomato); color: #fff;
  border: var(--stroke); border-radius: 999px;
  padding: 12px 20px; box-shadow: var(--shadow-small);
  cursor: pointer; text-decoration: none;
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: var(--shadow-small); }
.btn-light { background: var(--card); color: var(--ink); }
.btn-lemon { background: var(--lemon); color: var(--ink); }
.btn-mint { background: var(--mint); color: #fff; }
.btn-small { font-size: 15px; padding: 8px 14px; }

/* ---------- Game layout ---------- */
.game { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); max-width: 600px; width: 100%; margin: 0 auto; }
.column { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
@media (min-width: 880px) {
  .game { max-width: none; grid-template-columns: minmax(0, 600px) minmax(300px, 1fr); align-items: start; }
  .side { position: sticky; top: 12px; }
}

/* ---------- Player cards ---------- */
.player { display: flex; align-items: center; gap: 10px; min-height: 52px; }
.avatar {
  width: 44px; height: 44px; flex: none; border: var(--stroke); border-radius: 50%; display: grid; place-items: center;
  font-size: 22px; background: var(--plum-light); box-shadow: var(--shadow-small);
}
.player-you .avatar { background: var(--lemon); }
.player-info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.player-name { font: 700 18px/1.1 var(--font-display); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { font: 800 12px/1 var(--font-text); padding: 4px 8px; border: 2px solid var(--ink); border-radius: 999px; background: var(--card); letter-spacing: .03em; text-transform: uppercase; }
.captured { display: flex; align-items: center; min-height: 22px; flex-wrap: wrap; }
.captured i { width: 20px; height: 20px; margin-right: -6px; background-size: contain; background-repeat: no-repeat; }
.captured i.new-group { margin-left: 8px; }
.captured b { margin-left: 10px; font: 700 14px/1 var(--font-display); color: var(--text-2); font-variant-numeric: tabular-nums; }
.thinking { display: inline-flex; gap: 4px; align-items: center; margin-left: auto; }
.thinking span { width: 9px; height: 9px; border-radius: 50%; background: var(--plum); border: 2px solid var(--ink); animation: hop 1s ease-in-out infinite; }
.thinking span:nth-child(2) { animation-delay: .15s; } .thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-7px); } }

/* ---------- Board ---------- */
.frame { border: var(--stroke); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; background: var(--ink); }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1; width: 100%; max-width: 100%; touch-action: none; user-select: none; -webkit-user-select: none;
}
.square { position: relative; background: var(--square-light); cursor: default; }
.square.dark { background: var(--square-dark); }
.square.mine { cursor: grab; }
.square.last::before, .square.selected::before, .square.check::before, .square.hint::before { content: ""; position: absolute; inset: 0; }
.square.last::before { background: var(--trail); }
.square.selected::before { background: var(--selection); }
.square.check::before { background: radial-gradient(circle, var(--tomato) 0 30%, rgba(255,90,60,.55) 50%, transparent 72%); }
.square.hint::before { box-shadow: inset 0 0 0 4px var(--plum); background: rgba(122, 92, 250, .18); animation: blink 1s ease-in-out 3; }
@keyframes blink { 50% { background: rgba(122, 92, 250, .4); } }
.square.target { cursor: pointer; }
.square.target::after { content: ""; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; translate: -50% -50%; border-radius: 50%; background: var(--dot); z-index: 3; pointer-events: none; }
.square.target.capture::after { width: 88%; height: 88%; background: transparent; border: 5px solid var(--dot); }
.piece {
  position: absolute; inset: 5%; z-index: 2; pointer-events: none;
  background-size: contain; background-repeat: no-repeat; background-position: center;
}
.piece.flying { z-index: 6; transition: transform .22s cubic-bezier(.3,.7,.3,1); }
.piece.dragged { z-index: 7; scale: 1.15; filter: drop-shadow(3px 4px 0 rgba(29,21,51,.3)); }
.coord { position: absolute; z-index: 1; font: 800 11px/1 var(--font-text); pointer-events: none; color: var(--square-dark); }
.dark .coord { color: var(--square-light); }
.coord-rank { left: 4px; top: 4px; }
.coord-file { right: 4px; bottom: 3px; }
@media (min-width: 600px) { .coord { font-size: 12px; } }

/* ---------- Side panel ---------- */
.card { background: var(--card); border: var(--stroke); border-radius: var(--r); box-shadow: var(--shadow-small); padding: 14px; }
.message { display: flex; gap: 12px; align-items: center; background: var(--card); }
.message.alert { background: var(--tomato-light); }
.message.over { background: var(--lemon); }
.message-icon { font-size: 30px; line-height: 1; flex: none; }
.message h2 { font-size: 22px; }
.message p { margin: 2px 0 0; color: var(--text-2); font-weight: 700; font-size: 14px; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.action {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; cursor: pointer;
  background: var(--card); border: var(--stroke); border-radius: var(--r-small); box-shadow: var(--shadow-small);
  font: 800 13px/1.2 var(--font-text); color: var(--ink); min-width: 0;
}
.action span:first-child { font-size: 20px; line-height: 1.1; }
.action:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
.action:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: var(--shadow-small); }
.move-list-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.move-list-top h2 { font-size: 20px; }
.move-list-top small { color: var(--text-2); font-weight: 700; font-size: 13px; }
.move-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; display: grid; grid-template-columns: 2.6em 1fr 1fr; font-variant-numeric: tabular-nums; font-weight: 700; }
.move-list li { display: contents; }
.move-list .nr { color: var(--text-2); padding: 3px 0; }
.move-list .san { padding: 3px 8px; border-radius: 6px; }
.move-list li:nth-child(odd) span { background: var(--paper); }
.move-list .san.current { background: var(--lemon) !important; }
.move-list-empty { color: var(--text-2); font-weight: 700; font-size: 14px; margin: 0; }
@media (min-width: 880px) { .move-list { max-height: 300px; } }
.footer { text-align: center; font-size: 13px; color: var(--text-2); margin: 4px 0 0; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(29,21,51,.55); display: grid; place-items: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)); }
.modal-card { width: min(100%, 500px); max-height: 100%; overflow: auto; background: var(--paper); border: var(--stroke); border-radius: var(--r); box-shadow: var(--shadow); }
.modal-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; background: var(--mint-light); border-bottom: var(--stroke); }
.modal-top h2 { font-size: 21px; }
.modal-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.section-label { font: 800 12px/1 var(--font-text); text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin: 4px 0 -4px; }
.levels { display: flex; flex-direction: column; gap: 8px; }
.level {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; text-align: left; cursor: pointer; padding: 10px 12px;
  background: var(--card); border: var(--stroke); border-radius: var(--r-small); color: var(--ink);
}
.level[aria-pressed="true"] { background: var(--lemon); box-shadow: var(--shadow-small); transform: translate(-1px,-1px); }
.level-name { font: 700 18px/1.2 var(--font-display); }
.level-desc { grid-column: 1 / -1; font-size: 14px; color: var(--text-2); font-weight: 600; }
.level[aria-pressed="true"] .level-desc { color: var(--ink); }
.dots { display: inline-flex; gap: 3px; align-items: center; }
.dots i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); background: var(--card); }
.dots i.filled { background: var(--tomato); }
.balance { grid-column: 1 / -1; font-size: 12px; font-weight: 800; color: var(--text-2); font-variant-numeric: tabular-nums; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.color {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; cursor: pointer;
  background: var(--card); border: var(--stroke); border-radius: var(--r-small); font: 800 14px/1.2 var(--font-text); color: var(--ink);
}
.color[aria-pressed="true"] { background: var(--lemon); box-shadow: var(--shadow-small); transform: translate(-1px,-1px); }
.color i { width: 34px; height: 34px; background-size: contain; background-repeat: no-repeat; display: block; }
.color .random { font-style: normal; font-size: 26px; line-height: 34px; text-align: center; background: none; }
.buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.buttons .btn { flex: 1 1 140px; }
.promotion { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.promotion button { aspect-ratio: 1; max-width: 100%; border: var(--stroke); border-radius: var(--r-small); background: var(--square-light); cursor: pointer; box-shadow: var(--shadow-small); padding: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font: 800 12px var(--font-text); color: var(--ink); }
.promotion i { width: 70%; flex: 1; background-size: contain; background-repeat: no-repeat; background-position: center; display: block; }
.summary { text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.summary .big { font-size: 56px; line-height: 1; animation: jump .6s cubic-bezier(.3,1.6,.5,1); }
@keyframes jump { from { transform: scale(.3) rotate(-20deg); } }
.summary h3 { font-size: 28px; }
.summary p { margin: 0; color: var(--text-2); font-weight: 700; }
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.results div { background: var(--card); border: 2px solid var(--ink); border-radius: var(--r-small); padding: 6px; font-size: 12px; font-weight: 800; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.results b { display: block; font: 700 22px/1.1 var(--font-display); color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
