/* Crónicas de Catán — mar alrededor, losetas de arena, marco de madera */
:root {
  --mar: #0f3350;
  --mar-2: #17507a;
  --espuma: #9cc6df;
  --arena: #ecd9a8;
  --arena-2: #f7ecce;
  --madera: #5a3a22;
  --madera-2: #7b5434;
  --tinta: #2a1b10;
  --tinta-2: #6b5440;
  --bosque: #2f6b3a;
  --ladrillo: #b5532f;
  --cereal: #e3b23c;
  --pasto: #8fb84e;
  --mineral: #7d8597;
  --display: "Grenze Gotisch", "Palatino Linotype", Georgia, serif;
  --texto: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--texto);
  font-size: 17px;
  line-height: 1.4;
  color: var(--tinta);
  background-color: var(--mar);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='97' viewBox='0 0 56 97'%3E%3Cpath d='M28 0 56 16v32L28 64 0 48V16zM28 64v33M0 48v49M56 48v49' fill='none' stroke='%23ffffff' stroke-opacity='.06' stroke-width='1.5'/%3E%3C/svg%3E"),
    radial-gradient(120% 80% at 50% 0%, var(--mar-2), var(--mar) 70%);
  background-attachment: fixed;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
}

a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
:focus-visible { outline: 3px solid var(--cereal); outline-offset: 2px; }

/* ---------- Cabecera ---------- */
.top {
  padding: calc(var(--safe-t) + 10px) 16px 6px;
  display: flex; align-items: center; justify-content: center;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-hexes { width: 58px; height: 20px; }
.brand-text {
  font-family: var(--display); font-weight: 700; font-size: 26px;
  color: var(--cereal); letter-spacing: .01em;
  text-shadow: 0 2px 0 #06192a;
}

main { max-width: 560px; margin: 0 auto; padding: 6px 14px 0; outline: none; }

/* ---------- Tipografía ---------- */
h1, h2, h3 { font-family: var(--display); font-weight: 700; margin: 0; line-height: 1.1; }
.sea-title { color: var(--arena-2); font-size: 30px; margin: 18px 4px 10px; text-shadow: 0 2px 0 #06192a; }
.sea-sub { color: var(--espuma); margin: -6px 4px 14px; font-size: 16px; }
.tile h2 { font-size: 24px; color: var(--madera); margin-bottom: 10px; }
.muted { color: var(--tinta-2); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Losetas (paneles) ---------- */
.tile {
  background: var(--arena);
  background-image: radial-gradient(130% 90% at 30% 0%, var(--arena-2), var(--arena) 65%);
  border: 3px solid var(--madera);
  border-radius: 16px;
  box-shadow: 0 4px 0 #06192a;
  padding: 16px;
  margin-bottom: 16px;
}
.tile-flat { padding: 0; overflow: hidden; }

/* ---------- Hexágonos de avatar ---------- */
.hex {
  --s: 52px;
  --pc: var(--mineral);
  width: var(--s); height: calc(var(--s) * 1.1547);
  display: inline-grid; place-items: center; flex: none;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--pc);
  position: relative;
}
.hex-in {
  width: calc(100% - var(--b, 7px)); height: calc(100% - var(--b, 7px) * 1.1547);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--arena-2);
  display: grid; place-items: center; overflow: hidden;
}
.hex-in img { width: 100%; height: 100%; object-fit: cover; }
.hex .initial { font-family: var(--display); font-weight: 700; font-size: calc(var(--s) * .44); color: var(--tinta); line-height: 1; }
.hex-xs { --s: 26px; --b: 4px; }
.hex-s { --s: 36px; --b: 5px; }
.hex-m { --s: 52px; }
.hex-l { --s: 78px; --b: 9px; }
.hex-xl { --s: 132px; --b: 12px; }
.hex-empty { --pc: rgba(90, 58, 34, .35); }
.av-wrap { position: relative; display: inline-block; flex: none; }
.crown {
  position: absolute; left: 50%; top: -12px; transform: translateX(-50%);
  width: 26px; height: 18px; pointer-events: none;
  filter: drop-shadow(0 1px 0 #5a3a22);
}
.hex-xs + .crown, .hex-s + .crown { width: 18px; height: 12px; top: -8px; }

/* ---------- Selector de año ---------- */
.years { display: flex; gap: 8px; margin: 4px 0 14px; overflow-x: auto; padding: 2px; }
.years button {
  border: 2px solid var(--arena); background: transparent; color: var(--arena-2);
  border-radius: 999px; padding: 6px 16px; font-weight: 700; cursor: pointer; flex: none;
}
.years button[aria-pressed="true"] { background: var(--arena); color: var(--madera); }

/* ---------- Podio ---------- */
.podium { display: grid; grid-template-columns: 1fr 1.25fr 1fr; align-items: end; gap: 4px; text-align: center; padding-top: 18px; }
.podium a { text-decoration: none; display: grid; justify-items: center; gap: 4px; }
.podium .pname { font-family: var(--display); font-size: 20px; color: var(--tinta); line-height: 1; }
.podium .pwins { font-size: 14px; color: var(--tinta-2); }
.podium .place { font-family: var(--display); font-size: 16px; color: var(--madera-2); }
.podium .first .pname { font-size: 24px; }

/* ---------- Clasificación ---------- */
.rank { list-style: none; margin: 8px 0 0; padding: 0; }
.rank li + li { border-top: 1px dashed rgba(90, 58, 34, .35); }
.rank a { display: grid; grid-template-columns: 26px auto 1fr auto; align-items: center; gap: 10px; padding: 9px 2px; text-decoration: none; }
.rank .pos { font-family: var(--display); font-size: 20px; color: var(--madera-2); text-align: center; }
.rank .who b { display: block; font-size: 18px; }
.rank .who small { color: var(--tinta-2); font-size: 14px; }
.rank .wins { text-align: right; line-height: 1; }
.rank .wins b { font-family: var(--display); font-size: 30px; color: var(--ladrillo); }
.rank .wins small { display: block; font-size: 12px; color: var(--tinta-2); }

/* ---------- Partidas (crónica) ---------- */
.games { list-style: none; margin: 0; padding: 0; }
.game {
  display: block; text-decoration: none;
  background: var(--arena-2); border: 2px solid var(--madera-2); border-radius: 12px;
  padding: 12px 12px 10px; margin-bottom: 10px;
}
.game-head { display: flex; align-items: center; gap: 12px; }
.game-head .what { flex: 1; min-width: 0; }
.game-head .what b { font-size: 18px; }
.game-head .what span { display: block; color: var(--tinta-2); font-size: 14px; }
.game-head .wpts { font-family: var(--display); font-size: 30px; color: var(--ladrillo); line-height: 1; }
.game-rest { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px; padding-top: 8px; border-top: 1px dashed rgba(90, 58, 34, .35); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; }
.chip b { font-variant-numeric: tabular-nums; }
.game-note { margin: 8px 0 0; font-style: italic; color: var(--tinta-2); font-size: 15px; }
.month { color: var(--espuma); font-family: var(--display); font-size: 20px; margin: 16px 4px 8px; }

/* ---------- Jugadores ---------- */
.players-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px 8px; padding: 6px 0 4px; }
.players-grid a, .players-grid button {
  display: grid; justify-items: center; gap: 6px; text-decoration: none; background: none; border: 0; cursor: pointer; padding: 0;
}
.players-grid .pn { font-weight: 700; font-size: 16px; text-align: center; color: var(--tinta); }
.players-grid .ps { font-size: 13px; color: var(--tinta-2); margin-top: -6px; }
.add-hex .hex { --pc: var(--madera-2); }
.add-hex .hex-in { background: transparent; }
.add-hex .plus { font-family: var(--display); font-size: 40px; color: var(--arena-2); line-height: 1; }

/* ---------- Perfil ---------- */
.profile { text-align: center; padding-top: 22px; }
.profile h1 { font-size: 38px; color: var(--tinta); margin-top: 8px; }
.profile .since { color: var(--tinta-2); margin: 2px 0 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; text-align: center; }
.stat { background: var(--arena-2); border: 2px solid var(--madera-2); border-radius: 10px; padding: 8px 4px; }
.stat b { display: block; font-family: var(--display); font-size: 30px; line-height: 1.05; color: var(--madera); }
.stat span { font-size: 13px; color: var(--tinta-2); line-height: 1.15; display: block; }
.stat.hi b { color: var(--ladrillo); }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 110px; padding: 8px 0 0; overflow-x: auto; }
.bar { flex: 1 0 16px; max-width: 26px; display: grid; align-content: end; justify-items: center; gap: 2px; height: 100%; }
.bar i { display: block; width: 100%; border-radius: 4px 4px 0 0; background: var(--mineral); }
.bar.win i { background: var(--cereal); box-shadow: inset 0 0 0 2px var(--madera-2); }
.bar small { font-size: 11px; color: var(--tinta-2); font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 16px; font-size: 14px; color: var(--tinta-2); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }

.mygame { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 10px 2px; text-decoration: none; }
.mygame + .mygame { border-top: 1px dashed rgba(90, 58, 34, .35); }
.mygame .pts { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-size: 24px; background: var(--arena-2); border: 2px solid var(--madera-2); }
.mygame.win .pts { background: var(--cereal); }
.mygame .info b { display: block; }
.mygame .info span { font-size: 14px; color: var(--tinta-2); }
.mygame .rivals { display: flex; gap: 2px; }
.badge, .mygame .info .badge { display: inline-block; color: var(--arena-2); font-size: 13px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--bosque); margin-left: 6px; vertical-align: 1px; }

/* ---------- Formularios ---------- */
label.f { display: block; font-weight: 700; margin: 14px 0 6px; color: var(--madera); }
.f-hint { font-size: 14px; color: var(--tinta-2); margin: -2px 0 8px; font-weight: 400; }
input[type="text"], input[type="date"], input[type="number"], select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 2px solid var(--madera-2); background: var(--arena-2);
  font-size: 17px; min-height: 46px;
}
textarea { min-height: 90px; resize: vertical; }
input[type="date"] { -webkit-appearance: none; appearance: none; }

.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.colors button {
  width: 40px; height: 46px; border: 0; cursor: pointer;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--c); position: relative;
}
.colors button[aria-pressed="true"]::after {
  content: ""; position: absolute; inset: 14px 12px; border-radius: 50%; background: var(--arena-2); box-shadow: 0 0 0 2px var(--madera);
}

.photo-pick { display: flex; align-items: center; gap: 16px; }
.photo-pick .btns { display: grid; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--madera); background: var(--arena-2); color: var(--madera);
  font-weight: 700; text-decoration: none; font-size: 17px;
}
.btn-main { background: var(--ladrillo); border-color: #7d331b; color: #fff7e6; box-shadow: 0 3px 0 #7d331b; }
.btn-main:active { transform: translateY(2px); box-shadow: 0 1px 0 #7d331b; }
.btn-danger { border-color: #8f2a1c; color: #8f2a1c; background: transparent; }
.btn-block { width: 100%; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 15px; }
.actions { display: grid; gap: 10px; margin-top: 18px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Selección de jugadores en partida */
.pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 4px; }
.pick button { background: none; border: 0; padding: 0; display: grid; justify-items: center; gap: 4px; cursor: pointer; opacity: .45; font-size: 14px; font-weight: 700; }
.pick button[aria-pressed="true"] { opacity: 1; }
.pick button[aria-pressed="true"] .hex { outline: none; }
.pick button span.n { max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scores { list-style: none; margin: 0; padding: 0; }
.score { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 10px 0; }
.score + .score { border-top: 1px dashed rgba(90, 58, 34, .35); }
.score .nm { font-weight: 700; font-size: 18px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--madera); background: var(--arena-2);
  font-size: 24px; font-weight: 700; line-height: 1; cursor: pointer; color: var(--madera);
}
.stepper input { width: 58px; text-align: center; font-family: var(--display); font-size: 26px; padding: 4px; min-height: 42px; }
.winner-pick { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--tinta-2); margin-top: -2px; }
.winner-pick input { width: 22px; height: 22px; accent-color: var(--ladrillo); }
.score.is-winner .nm::after { content: " gana"; color: var(--ladrillo); font-weight: 700; font-size: 15px; }

/* Vacío */
.empty { text-align: center; padding: 26px 12px; }
.empty p { margin: 8px 0 16px; color: var(--tinta-2); }
.empty .hexrow { display: flex; justify-content: center; gap: 4px; margin-bottom: 4px; }

/* Más */
.menu { list-style: none; margin: 0; padding: 0; }
.menu li + li { border-top: 1px dashed rgba(90, 58, 34, .35); }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: 14px 4px; background: none; border: 0; text-decoration: none; cursor: pointer; }
.menu b { display: block; font-size: 18px; }
.menu span { color: var(--tinta-2); font-size: 15px; }

/* Importar */
.imp-game { background: var(--arena-2); border: 2px solid var(--madera-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.imp-game.off { opacity: .5; }
.imp-top { display: flex; gap: 10px; align-items: center; }
.imp-top input[type="date"] { flex: 1; min-height: 40px; padding: 6px 10px; }
.imp-top label { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 700; }
.imp-top input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--bosque); }
.imp-rows { margin: 8px 0 4px; font-size: 16px; }
.imp-raw { font-size: 13px; color: var(--tinta-2); white-space: pre-wrap; margin: 6px 0 0; }
.imp-warn { color: #8f2a1c; font-size: 14px; font-weight: 700; margin: 6px 0 0; }
.map-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; align-items: center; padding: 6px 0; }
.map-row b { font-size: 17px; }

/* Navegación inferior: marco de madera */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  height: calc(var(--nav-h) + var(--safe-b)); padding: 0 6px var(--safe-b);
  background: linear-gradient(var(--madera-2), var(--madera));
  border-top: 3px solid #3b2514;
}
.tabs a {
  display: grid; justify-items: center; gap: 2px; padding: 8px 0 10px;
  color: var(--arena); text-decoration: none; font-size: 12px; font-weight: 700; opacity: .75;
}
.tabs a svg { width: 24px; height: 24px; fill: currentColor; }
.tabs a[aria-current="page"] { opacity: 1; color: var(--cereal); }
.tab-new-hex {
  width: 58px; height: 66px; margin-top: -30px; display: grid; place-items: center;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--ladrillo);
  box-shadow: inset 0 0 0 4px #7d331b;
}
.tabs .tab-new { opacity: 1; }
.tab-new-hex svg { width: 30px !important; height: 30px !important; fill: #fff7e6 !important; }

/* Aviso */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); transform: translate(-50%, 20px);
  background: var(--tinta); color: var(--arena-2); padding: 10px 16px; border-radius: 10px;
  max-width: calc(100% - 32px); font-size: 15px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.back { display: inline-flex; align-items: center; gap: 6px; color: var(--espuma); text-decoration: none; margin: 10px 4px 0; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (min-width: 600px) {
  .players-grid { grid-template-columns: repeat(4, 1fr); }
}
