@font-face { font-family: 'Patrick Hand'; src: url('../fonts/patrick-hand.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Permanent Marker'; src: url('../fonts/permanent-marker.woff2') format('woff2'); font-display: swap; }

:root {
  --paper: #f3efe4; --paper-2: #ebe5d6; --ink: #16161a; --graphite: #3a3b40; --soft: rgba(22, 22, 26, 0.62);
  --power: #e23a2e; --glow: #ff7a3d;
  --sketch: 255px 15px 225px 15px / 15px 225px 15px 255px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); overscroll-behavior: none; }
body { font-family: 'Patrick Hand', 'Comic Sans MS', system-ui, sans-serif; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }

.ui { position: fixed; inset: 0; display: grid; place-items: center; padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); overflow-y: auto; }
.ui[hidden], .screen[hidden] { display: none; }
.screen { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 100%; }

/* Título */
.title { background: radial-gradient(ellipse at center, rgba(243,239,228,0.97) 45%, rgba(243,239,228,0.8) 70%, rgba(243,239,228,0) 100%); padding: 22px 64px; }
.logo { font-family: 'Permanent Marker', sans-serif; font-weight: 400; font-size: clamp(46px, 11vmin, 112px); line-height: 0.9; margin: 0; letter-spacing: 1px; transform: rotate(-3deg); text-align: center; }
.logo span:last-child { display: inline-block; transform: translateY(4px) rotate(2deg); }
.underline { width: min(420px, 70vw); height: 22px; margin-top: -4px; transform: rotate(-2deg); }
.underline path { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; }
.underline path.red { stroke: var(--power); stroke-width: 4; filter: drop-shadow(0 0 3px var(--glow)); }
.tagline { margin: 0 0 4px; font-size: clamp(18px, 3.4vmin, 24px); color: var(--soft); }
.menu { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.menu .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.studio { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 6px; font-size: 15px; color: var(--soft); }
.studio img { height: 40px; width: auto; }
.build { font-size: 12px; opacity: 0.7; }

/* Botones dibujados a mano */
.btn { font: inherit; font-size: 22px; color: var(--ink); background: rgba(243,239,228,0.92); border: 2.5px solid var(--ink); border-radius: var(--sketch); padding: 6px 22px 7px; cursor: pointer; min-height: 44px; min-width: 120px; transition: transform .08s ease, background .12s; box-shadow: 2px 3px 0 rgba(22,22,26,0.18); }
.btn:hover { transform: rotate(-1deg) scale(1.03); background: #fffdf6; }
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn:focus-visible { outline: 3px dashed var(--ink); outline-offset: 4px; }
.btn.big { font-family: 'Permanent Marker', sans-serif; font-size: clamp(26px, 5vmin, 34px); padding: 6px 42px 10px; display: flex; flex-direction: column; align-items: center; line-height: 1.05; }
.btn.big small { font-family: 'Patrick Hand', sans-serif; font-size: 16px; color: var(--soft); }

/* Tarjetas */
.card { background: var(--paper); border: 2.5px solid var(--ink); border-radius: var(--sketch); padding: 18px 26px 20px; box-shadow: 4px 6px 0 rgba(22,22,26,0.14); min-width: min(360px, 92vw); max-height: calc(100dvh - 24px); overflow-y: auto; background-image: repeating-linear-gradient(transparent 0 33px, rgba(96,108,128,0.14) 33px 34px); }
.card.wide { max-width: min(640px, 94vw); }
.card h2 { font-family: 'Permanent Marker', sans-serif; font-weight: 400; font-size: 34px; margin: 0 0 4px; transform: rotate(-2deg); }
.field { display: grid; grid-template-columns: 1fr 1.2fr; align-items: center; gap: 12px; width: 100%; font-size: 20px; }
.field select { font: inherit; font-size: 19px; background: #fffdf6; border: 2px solid var(--ink); border-radius: 10px 4px 12px 3px; padding: 2px 8px; color: var(--ink); }
input[type=range] { accent-color: var(--ink); width: 100%; }
.check { display: flex; gap: 10px; align-items: center; width: 100%; font-size: 19px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--ink); }
.keys { border-collapse: collapse; font-size: 18px; width: 100%; }
.keys td { padding: 3px 6px; vertical-align: top; }
.keys td:first-child { white-space: nowrap; color: var(--soft); }
.keys td.pow { color: var(--power); }
kbd { font-family: inherit; border: 1.8px solid var(--ink); border-radius: 6px 3px 7px 2px; padding: 0 6px; background: #fffdf6; margin-right: 2px; }
.note { margin: 2px 0; font-size: 17px; color: var(--soft); text-align: left; width: 100%; }
.credits { white-space: pre-line; font-size: 18px; text-align: center; margin: 4px 0; }
.credits-logo { width: 220px; height: auto; }
.copy { font-size: 14px; color: var(--soft); margin: 0; }

.loading { position: fixed; inset: 0; display: grid; place-items: center; font-size: 24px; background: var(--paper); }
.loading[hidden] { display: none; }
.rotate { position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--paper); border: 2px solid var(--ink); border-radius: var(--sketch); padding: 6px 16px; font-size: 17px; z-index: 5; pointer-events: none; }
.rotate[hidden], .fatal[hidden] { display: none; }
.fatal { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); background: #fffdf6; border: 2px solid var(--ink); padding: 8px 16px; border-radius: 8px; z-index: 9; }

@media (max-height: 460px) {
  .title { padding: 6px 24px; gap: 4px; }
  .studio img { height: 30px; }
  .btn { font-size: 19px; min-height: 40px; padding: 4px 16px; }
  .card { padding: 10px 18px 12px; }
  .card h2 { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } }

.note.center { text-align: center; margin: 0; }
.power-picker { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.btn.pw { min-width: 0; font-size: 18px; padding: 4px 12px 6px; display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.btn.pw small { font-size: 13px; color: var(--soft); }
.btn.pw .dot { width: 26px; height: 6px; border-radius: 4px; background: var(--pc); box-shadow: 0 0 8px var(--pc); margin-bottom: 3px; }
.btn.pw.on { border-color: var(--pc); border-width: 3.5px; background: #fffdf6; }
.sub { font-family: 'Permanent Marker', sans-serif; font-weight: 400; font-size: 22px; margin: 8px 0 0; width: 100%; }
.moves { margin: 2px 0; padding-left: 20px; font-size: 17px; width: 100%; text-align: left; }
.moves li { margin: 1px 0; }
.moves li.p1::marker { color: #e23a2e; } .moves li.p2::marker { color: #2f5fe0; } .moves li.p3::marker { color: #d9a800; }

/* Selector de hojas */
.pages { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; width: 100%; margin: 4px 0 6px; }
.page-tile { font: inherit; color: var(--ink); background: #fffdf6; border: 2.5px solid var(--ink); border-radius: 6px 3px 9px 2px; padding: 8px 6px 10px; display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: 84px; cursor: pointer; position: relative; box-shadow: 3px 4px 0 rgba(22,22,26,0.15); background-image: repeating-linear-gradient(transparent 0 15px, rgba(96,108,128,0.16) 15px 16px); transition: transform .08s; }
.page-tile:hover { transform: rotate(-1.5deg) translateY(-2px); }
.page-tile:focus-visible { outline: 3px dashed var(--ink); outline-offset: 3px; }
.page-tile::after { content: ''; position: absolute; right: -2px; bottom: -2px; width: 16px; height: 16px; background: linear-gradient(135deg, #e3dccb 50%, var(--paper) 50%); border-left: 2px solid var(--ink); border-top: 2px solid var(--ink); }
.page-tile .pn { font-family: 'Permanent Marker', sans-serif; font-size: 20px; }
.page-tile .pname { font-size: 16px; line-height: 1.05; text-align: center; }
.page-tile .pbest { font-size: 14px; color: var(--soft); }
.page-tile .pbest.new { font-style: italic; }
.page-tile.locked { cursor: default; opacity: 0.45; box-shadow: none; background-image: repeating-linear-gradient(45deg, transparent 0 7px, rgba(58,59,64,0.12) 7px 8px); }
.page-tile.locked:hover { transform: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn[disabled] { opacity: 0.5; cursor: default; transform: none; }

/* Resultados */
.results h2 { font-size: 36px; }
.grade-wrap { display: flex; align-items: center; gap: 18px; }
.grade { width: 96px; height: 96px; display: grid; place-items: center; border: 4px solid var(--ink); border-radius: 52% 48% 55% 45% / 50% 55% 45% 50%; transform: rotate(-8deg); font-family: 'Permanent Marker', sans-serif; font-size: 50px; line-height: 1; animation: stamp .35s cubic-bezier(.2,1.6,.4,1) both .15s; }
.grade-side { display: flex; flex-direction: column; gap: 4px; }
.grade-word { font-family: 'Permanent Marker', sans-serif; font-size: 26px; transform: rotate(-3deg); }
.record { font-size: 18px; border-bottom: 2px solid var(--ink); align-self: flex-start; }
.record[hidden] { display: none; }
.stats { border-collapse: collapse; font-size: 19px; min-width: 260px; }
.stats td { padding: 1px 10px; }
.stats td:last-child { text-align: right; font-family: 'Permanent Marker', sans-serif; font-size: 18px; }
@keyframes stamp { from { transform: scale(2.2) rotate(-20deg); opacity: 0; } to { transform: scale(1) rotate(-8deg); opacity: 1; } }

/* Vuelta de página */
.flip { position: fixed; inset: 0; z-index: 8; perspective: 1600px; pointer-events: none; background: var(--paper); }
.flip[hidden] { display: none; }
.flip .sheet { position: absolute; inset: 0; background-size: cover; background-position: center; transform-origin: 0% 50%; transition: transform .9s cubic-bezier(.55,.05,.4,1), box-shadow .9s; box-shadow: 0 0 0 rgba(0,0,0,0); }
.flip .sheet-shade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,0) 40%, rgba(40,30,20,0.0)); transition: background .9s; }
.flip.go .sheet { transform: rotateY(-115deg) skewY(-2deg); box-shadow: 40px 0 60px rgba(40,30,20,0.35); }
.flip.go .sheet-shade { background: linear-gradient(90deg, rgba(0,0,0,0) 0%, rgba(40,30,20,0.45)); }
@media (max-height: 460px) { .page-tile { min-height: 64px; padding: 4px; } .page-tile .pn { font-size: 17px; } .grade { width: 72px; height: 72px; font-size: 38px; } .results h2 { font-size: 26px; } .stats { font-size: 16px; } }
@media (max-width: 520px) { .pages { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (prefers-reduced-motion: reduce) { .grade { animation: none; } .flip .sheet { transition: none; } }

.unlock-line { margin: 0; font-family: 'Permanent Marker', sans-serif; font-size: 20px; color: var(--pc, var(--power)); text-shadow: 0 0 8px var(--pc, var(--glow)); }
.unlock-line[hidden] { display: none; }
/* resultados en teléfono horizontal: calificación y estadísticas lado a lado */
@media (max-height: 460px) {
  .results { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; column-gap: 26px; row-gap: 4px; }
  .results h2, .results .unlock-line, .results nav { width: 100%; text-align: center; }
  .results .unlock-line { font-size: 17px; }
  .results .stats td { padding: 0 8px; line-height: 1.15; }
  .results .stats td:last-child { font-size: 15px; }
}
@media (max-height: 460px) {
  .card.wide.results { max-width: 96vw; padding: 8px 18px 10px; }
  .results h2 { margin: 0; }
  .results .grade-wrap { gap: 10px; }
  .results .grade { width: 62px; height: 62px; font-size: 32px; }
  .results .grade-word { font-size: 20px; }
  .results .stats { min-width: 0; font-size: 15px; }
  .results .menu { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px; }
  .results .btn.big { font-size: 20px; padding: 3px 18px 5px; }
}

/* Duelo */
.btn.big { position: relative; }
.badge { position: absolute; top: -8px; right: -8px; min-width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--paper); font-family: 'Patrick Hand', sans-serif; font-size: 15px; display: grid; place-items: center; }
.badge[hidden] { display: none; }
.duel { gap: 8px; }
.duel-head { display: flex; justify-content: space-between; align-items: center; width: 100%; font-size: 20px; gap: 10px; flex-wrap: wrap; }
.arena-pick select { font: inherit; font-size: 17px; background: #fffdf6; border: 2px solid var(--ink); border-radius: 8px 3px 9px 2px; padding: 1px 6px; color: var(--ink); }
.bots { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; width: 100%; }
.bot-card { font: inherit; color: var(--ink); background: #fffdf6; border: 2.5px solid var(--ink); border-radius: 6px 3px 9px 2px; padding: 6px 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 0; cursor: pointer; box-shadow: 3px 4px 0 rgba(22,22,26,0.15); transition: transform .08s; }
.bot-card:hover { transform: rotate(-1.2deg) translateY(-2px); }
.bot-card:focus-visible { outline: 3px dashed var(--ink); outline-offset: 3px; }
.bot-card canvas { width: 64px; height: 64px; }
.bot-card .bn { font-family: 'Permanent Marker', sans-serif; font-size: 15px; line-height: 1.05; text-align: center; }
.bot-card .bs { font-size: 13px; color: var(--soft); text-align: center; line-height: 1.1; }
.bot-card .bd { font-size: 13px; letter-spacing: 1px; }
.bot-card .br { font-size: 14px; margin-top: 2px; }
.tag-bot { font-size: 11px; border: 1.5px solid var(--ink); border-radius: 4px; padding: 0 4px; margin-left: 4px; font-family: 'Patrick Hand', sans-serif; vertical-align: middle; }
.challenges { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.challenge { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 2.5px dashed var(--ink); border-radius: 8px 3px 10px 3px; padding: 6px 10px; background: #fffdf6; font-size: 18px; }
.challenge .btn { min-width: 0; font-size: 18px; padding: 2px 14px; min-height: 36px; }
.friends-note { width: 100%; font-size: 15px; color: var(--soft); border-top: 1.5px dashed rgba(22,22,26,0.3); padding-top: 6px; display: flex; flex-direction: column; }
.friends-note strong { color: var(--ink); font-weight: 400; font-family: 'Permanent Marker', sans-serif; font-size: 16px; }
.dr-score { font-family: 'Permanent Marker', sans-serif; font-size: 30px; margin: 0; }
.dr-record { font-size: 20px; margin: 0; }
@media (max-width: 760px) { .bots { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-height: 460px) { .bots { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; } .bot-card canvas { width: 46px; height: 46px; } .bot-card .bs { display: none; } .bot-card { padding: 3px; } .duel h2 { font-size: 24px; margin: 0; } .friends-note { font-size: 13px; } }

/* Cuenta y amigos */
.account { gap: 8px; }
.account h2 { margin-bottom: 0; }
.acc-form { display: flex; flex-direction: column; gap: 8px; width: min(420px, 86vw); align-items: stretch; margin: 0 auto; }
.fld { display: flex; flex-direction: column; font-size: 17px; gap: 2px; }
.fld input, .acc-inline input { font: inherit; font-size: 19px; background: #fffdf6; border: 2px solid var(--ink); border-radius: 8px 3px 9px 2px; padding: 5px 9px; color: var(--ink); }
.fld input:focus, .acc-inline input:focus { outline: 3px dashed var(--ink); outline-offset: 2px; }
.check.small { font-size: 15px; align-items: flex-start; }
.check.small input { margin-top: 3px; flex: none; }
.linkbtn { font: inherit; font-size: 16px; background: none; border: none; text-decoration: underline; color: var(--ink); cursor: pointer; padding: 2px 4px; }
.acc-msg { margin: 0; font-size: 16px; border-left: 4px solid var(--ink); padding: 3px 8px; background: #fffdf6; }
.acc-msg.ok { border-left-style: double; }
.code-box { display: flex; align-items: center; gap: 10px; border: 2.5px dashed var(--ink); border-radius: 8px; padding: 6px 12px; background: #fffdf6; font-size: 17px; }
.code-box strong { font-family: 'Permanent Marker', sans-serif; font-size: 26px; letter-spacing: 3px; font-weight: 400; }
.acc-inline { display: flex; gap: 8px; width: min(420px, 86vw); }
.acc-inline input { flex: 1; min-width: 0; text-transform: uppercase; }
.acc-inline input[name=name] { text-transform: none; }
.btn.sm { min-width: 0; font-size: 16px; padding: 1px 10px; min-height: 34px; }
.btn.danger { border-style: dashed; }
.friends { width: min(520px, 90vw); }
.friends h3 { font-family: 'Permanent Marker', sans-serif; font-weight: 400; font-size: 18px; margin: 6px 0 2px; }
.fr-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1.5px dashed rgba(22,22,26,0.25); padding: 3px 0; font-size: 18px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); margin-right: 8px; vertical-align: middle; }
.dot.on { background: var(--ink); }
.acc-more { width: min(520px, 90vw); font-size: 16px; }
.acc-more summary { cursor: pointer; text-decoration: underline; }
.acc-more > * { margin-top: 8px; }
.legal { max-width: min(720px, 96vw); text-align: left; }
.legal-body { max-height: 62dvh; overflow-y: auto; font-size: 16px; line-height: 1.35; padding-right: 6px; }
.legal-body h3 { font-family: 'Permanent Marker', sans-serif; font-weight: 400; font-size: 17px; margin: 10px 0 2px; }
.legal-body p { margin: 0; }
.legal-note { margin-top: 12px !important; font-size: 14px; color: var(--soft); }
.card a { color: var(--ink); }

/* ── en línea: amigos en Duelo, aviso, sala, resultado y ranking ── */
.net-box { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.net-box .friends { width: 100%; }
.net-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.net-head strong { font-family: 'Permanent Marker', sans-serif; font-weight: 400; font-size: 20px; }
.challenge.hot { border-style: solid; box-shadow: 3px 3px 0 var(--ink); }
.challenge em { font-style: normal; color: var(--soft); }
.recent { margin: 0; padding-left: 18px; font-size: 15px; color: var(--soft); }
.net-banner[hidden] { display: none; }
.net-banner { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%) rotate(-0.6deg); z-index: 5;
  display: flex; align-items: center; gap: 10px; background: #fffdf6; border: 2.5px solid var(--ink); border-radius: 9px 3px 10px 4px;
  box-shadow: 3px 3px 0 var(--ink); padding: 4px 6px 4px 12px; font-size: 17px; max-width: calc(100vw - 24px); }
.lobby-status { font-size: 22px; text-align: center; min-height: 1.4em; margin: 6px 0; }
.lobby-status.busy::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
@media (prefers-reduced-motion: reduce) { .lobby-status.busy::after { animation: none; } }
.dr-points { font-family: 'Permanent Marker', sans-serif; font-size: 22px; margin: 0; text-align: center; }
.tabs { justify-content: center; }
.btn.on { background: var(--ink); color: #fffdf6; }
table.rank { width: 100%; border-collapse: collapse; font-size: 18px; }
table.rank th { font-weight: 400; color: var(--soft); text-align: left; border-bottom: 2px solid var(--ink); }
table.rank td { border-bottom: 1.5px dashed rgba(22,22,26,0.25); padding: 2px 4px; }
table.rank td:first-child, table.rank th:first-child { width: 2.5em; }
table.rank tr.me td { font-weight: 700; background: rgba(242,194,27,0.18); }
.ranking #rank-body { width: 100%; max-height: 52vh; overflow-y: auto; }

.duel-top { width: 100%; display: flex; justify-content: flex-end; margin-top: -6px; }
.fr-row .row { flex-wrap: nowrap; align-items: center; gap: 8px; }
@media (min-width: 560px) { .duel-top { margin-top: -46px; margin-bottom: 4px; } }
.net-box .friends, .net-box .fr-row { width: 100%; max-width: 100%; box-sizing: border-box; }
.net-box .fr-row > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
