/* Kapec World — interface on top of the canvas. The world itself is drawn in js/art.js. */
:root {
  --ink: #2f2545;
  --lift: 0 4px 0 var(--ink), 0 10px 22px rgba(30, 20, 60, .22);
  --paper: #fffaf0;
  --sun: #ffc94d;
  --accent: #ff7a59;
  --font: 'Baloo 2', ui-rounded, 'SF Pro Rounded', 'Nunito', 'Trebuchet MS', system-ui, sans-serif;
  --sys: ui-rounded, system-ui, -apple-system, 'Segoe UI', 'Noto Sans', 'Noto Sans CJK SC', 'Noto Sans Arabic', 'Noto Sans Devanagari', sans-serif;
  --top: max(12px, env(safe-area-inset-top));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: #5e9e4f;
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}
html.sysfont body, html.sysfont button { font-family: var(--sys); }
button { font: inherit; color: inherit; cursor: pointer; }

.stage { position: fixed; inset: 0; }
#world { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; outline: none; }

[data-ic] svg { width: 1.2em; height: 1.2em; display: block; }

/* top bar */
.top {
  position: fixed; inset-inline: 0; top: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: var(--top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.logo {
  display: flex; gap: 3px; direction: ltr;
  font-family: var(--font); font-weight: 800; font-size: 26px; line-height: 1;
}
.logo span {
  display: grid; place-items: center; width: 34px; height: 38px; border-radius: 10px;
  color: #fff; border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink), 0 8px 16px rgba(30, 20, 60, .2);
  text-shadow: 0 2px 0 rgba(47, 37, 69, .55); padding-top: 3px;
  background-image: linear-gradient(180deg, rgba(255,255,255,.35), rgba(255,255,255,0) 55%);
}
.logo span:nth-child(1) { background-color: #ff6b6b; transform: rotate(-5deg); }
.logo span:nth-child(2) { background-color: #ffc94d; transform: translateY(3px) rotate(3deg); }
.logo span:nth-child(3) { background-color: #5ee6a8; transform: rotate(-2deg); }
.logo span:nth-child(4) { background-color: #5cc4ff; transform: translateY(3px) rotate(4deg); }
.logo span:nth-child(5) { background-color: #a98bff; transform: rotate(-4deg); }
.tools { display: flex; gap: 8px; }
.round {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(180deg, #ffffff, #f3ecdf); border: 3px solid var(--ink); box-shadow: var(--lift);
  font-size: 22px; padding: 0; transition: transform .08s, box-shadow .08s;
}
.round:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.round.small { width: 42px; height: 42px; font-size: 18px; box-shadow: 0 3px 0 var(--ink); }
.round:hover { filter: brightness(1.04); }
.round[aria-pressed="false"] { background: #e6e0ef; }
.round:focus-visible, .btn:focus-visible, .langs button:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }
/* the profile button shows the player's own character */
#btnProfile { overflow: hidden; background: linear-gradient(180deg, #d3f1ff, #9fdcfa); }
#btnProfile canvas { display: block; width: 100%; height: 100%; }

/* first-visit hint */
.hint {
  position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  margin: 0; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px);
  padding: 8px 16px; border-radius: 999px; background: rgba(255, 250, 240, .95);
  border: 3px solid var(--ink); box-shadow: var(--lift);
  font-weight: 800; font-size: 18px; white-space: nowrap; pointer-events: none;
  transition: opacity .5s, transform .5s;
  animation: bob 1.6s ease-in-out infinite;
}
.hint.gone { opacity: 0; transform: translate(-50%, 20px); animation: none; }
.hint-ic { font-size: 22px; color: var(--accent); }
@keyframes bob { 50% { margin-top: 5px; } }

/* "enter the game" panel */
.panel {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%); width: min(460px, calc(100% - 24px));
  display: grid; grid-template-columns: 64px 1fr; grid-template-rows: auto auto; gap: 6px 12px; align-items: center;
  padding: 12px 14px 14px; border-radius: 26px;
  background:
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--game, #ffc94d) 26%, transparent), transparent 60%),
    linear-gradient(180deg, #ffffff, #fbf4e8);
  border: 3px solid var(--ink); box-shadow: 0 6px 0 var(--ink), 0 18px 40px rgba(30, 20, 60, .3);
  animation: pop .28s cubic-bezier(.3, 1.6, .5, 1);
}
.panel[hidden] { display: none; }
.thumb {
  grid-row: 1 / 3; width: 64px; height: 64px; border-radius: 18px; border: 3px solid var(--ink);
  background: radial-gradient(circle at 50% 30%, #f4ffe9, #b9e59a);
  box-shadow: inset 0 -6px 0 rgba(47, 37, 69, .12);
}
.pname { font-size: 22px; line-height: 1.1; overflow-wrap: anywhere; text-align: start; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px;
  padding: 6px 18px; border-radius: 18px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(180deg, #ff9a6a 0%, #ff6a55 55%, #f2524f 100%);
  border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink), inset 0 2px 0 rgba(255,255,255,.45);
  font-weight: 800; font-size: 21px; line-height: 1.1;
  text-shadow: 0 2px 0 rgba(47, 37, 69, .4);
}
.btn::after {
  content: ''; position: absolute; top: -20%; bottom: -20%; width: 34%; left: -50%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  transform: skewX(-20deg); animation: shine 2.4s ease-in-out infinite;
}
@keyframes shine { 0%, 55% { left: -50%; } 100% { left: 130%; } }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn [data-ic] { font-size: 20px; }
@keyframes pop { from { transform: translateX(-50%) scale(.7); opacity: 0; } }


/* dialogs */
.modal {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(40, 30, 60, .45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.modal[hidden] { display: none; }
.sheet {
  width: min(520px, 100%); max-height: min(640px, calc(100dvh - 32px)); display: flex; flex-direction: column;
  background: linear-gradient(180deg, #ffffff, #fbf4e8); border: 3px solid var(--ink); border-radius: 26px;
  box-shadow: 0 6px 0 var(--ink), 0 24px 50px rgba(30, 20, 60, .35);
  padding: 14px 16px 16px; animation: pop2 .25s cubic-bezier(.3, 1.6, .5, 1);
}
@keyframes pop2 { from { transform: scale(.8); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sheet h2 { margin: 0; font-size: 24px; display: flex; align-items: center; gap: 8px; }
.langs { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; padding: 2px 4px 6px; }
.langs button {
  min-height: 46px; padding: 6px 10px; border-radius: 14px; border: 3px solid var(--ink);
  background: #fff; font-family: var(--sys); font-weight: 700; font-size: 16px; text-align: start;
}
.langs button[aria-current="true"] { background: var(--sun); }
.share { align-items: center; text-align: center; }
.share .sheet-head { width: 100%; }
.share p { margin: 0 0 12px; font-weight: 600; font-size: 16px; }
.share img { width: min(220px, 60vw); height: auto; background: #fff; border-radius: 12px; padding: 6px; margin-bottom: 12px; }
.share code { font: 700 18px ui-monospace, SFMono-Regular, Menlo, monospace; background: #fff; border-radius: 12px; padding: 8px 12px; overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }

/* character creator: a screen of its own over the world. The canvas paints the whole backdrop
   and the character; the bar, the stage (where the character is turned) and the panel lie on it. */
.creator {
  position: fixed; inset: 0; display: flex; flex-direction: column; background: #62c6f2;
  animation: crIn .3s ease-out;
}
.creator.leaving { animation: crOut .28s ease-in forwards; pointer-events: none; }
@keyframes crIn { from { opacity: 0; transform: scale(1.05); } }
@keyframes crOut { to { opacity: 0; transform: scale(1.05); } }
#crCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cr-top {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: var(--top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}
.cr-top h2 {
  margin: 0; min-width: 0; padding: 7px 16px 5px; border-radius: 999px; text-align: center;
  font-size: 21px; line-height: 1.1; overflow-wrap: anywhere;
  background: rgba(255, 250, 240, .96); border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink);
}
.cr-stage {
  position: relative; flex: 1; min-height: 130px; display: flex; align-items: flex-end; justify-content: space-between;
  padding: 0 14px 12px; touch-action: none; cursor: grab;
}
.cr-stage:active { cursor: grabbing; }
.cr-panel {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: linear-gradient(180deg, #ffffff, #fbf4e8); border-top: 3px solid var(--ink); border-radius: 26px 26px 0 0;
  box-shadow: 0 -8px 26px rgba(30, 20, 60, .22);
}
.cr-tabs { display: flex; gap: 5px; }
.cr-tab {
  flex: 1 1 0; min-width: 0; height: 46px; padding: 0; display: grid; place-items: center; font-size: 21px;
  border-radius: 14px; border: 3px solid var(--ink); background: #fff; box-shadow: 0 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.cr-tab[aria-selected="true"] { background: var(--sun); transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.cr-opts { display: flex; flex-direction: column; justify-content: center; gap: 10px; min-height: 164px; }
.cr-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.cr-row.off { opacity: .3; }
.cr-kinds { flex-wrap: nowrap; }
.cr-tile {
  flex: 0 1 68px; min-width: 0; aspect-ratio: 1; padding: 0; overflow: hidden;
  border-radius: 16px; border: 3px solid var(--ink); background: radial-gradient(circle at 50% 35%, #f4fcff, #c5eafd);
  transition: transform .1s;
}
.cr-tile canvas { display: block; width: 100%; height: 100%; }
.cr-tile[aria-pressed="true"] { background: radial-gradient(circle at 50% 35%, #fff6c9, var(--sun)); box-shadow: 0 0 0 3px var(--accent); transform: scale(1.04); }
.cr-sw {
  width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border-radius: 50%;
  border: 3px solid var(--ink); background: var(--c);
  box-shadow: inset 0 -5px 0 rgba(47, 37, 69, .16), inset 0 3px 0 rgba(255, 255, 255, .4);
  transition: transform .1s;
}
.cr-sw[aria-pressed="true"] { transform: scale(1.12); box-shadow: 0 0 0 3px var(--accent), inset 0 -5px 0 rgba(47, 37, 69, .16); }
.cr-sw[aria-pressed="true"]::after { content: ''; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--ink); }
.cr-tab:focus-visible, .cr-tile:focus-visible, .cr-sw:focus-visible, .cr-panel .btn:focus-visible { outline: 4px solid #3d7bff; outline-offset: 2px; }
.cr-tile:active, .cr-sw:active { transform: scale(.94); }
#crDone { align-self: center; min-width: min(280px, 100%); background: linear-gradient(180deg, #7fe08f 0%, #3fc46b 55%, #2aa85a 100%); }

.fade { position: fixed; inset: 0; background: #fffaf0; opacity: 0; pointer-events: none; transition: opacity .35s; }
.fade.start { opacity: 1; transition: opacity .6s .1s; }
.fade.on { opacity: 1; pointer-events: auto; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sr-only a:focus { position: fixed; top: 80px; left: 16px; width: auto; height: auto; clip: auto; background: #fff; padding: 8px; z-index: 9; }

/* narrow phones: the logo and the buttons of the bar get smaller, so that all of them fit */
@media (max-width: 430px) {
  .logo { font-size: 23px; }
  .logo span { width: 30px; height: 34px; border-radius: 9px; }
  .tools { gap: 6px; }
  .tools .round { width: 42px; height: 42px; font-size: 19px; }
}
@media (max-width: 374px) {
  .logo { font-size: 21px; gap: 2px; }
  .logo span { width: 28px; height: 32px; }
  .tools .round { width: 40px; height: 40px; }
  .cr-top h2 { font-size: 18px; padding-inline: 12px; }
}
@media (max-height: 600px) {
  .cr-tab { height: 40px; }
  .cr-opts { min-height: 150px; gap: 8px; }
  .cr-sw { width: 36px; height: 36px; }
  .cr-panel { gap: 8px; padding-top: 10px; }
  #crDone { min-height: 46px; }
}
/* wide screens: the character on one side, the choices on the other */
@media (min-width: 700px) and (min-aspect-ratio: 11/10) {
  .creator { display: grid; grid-template-columns: 1fr minmax(340px, 440px); grid-template-rows: auto 1fr; }
  .cr-top { grid-column: 1; }
  .cr-stage { grid-column: 1; }
  .cr-panel {
    grid-column: 2; grid-row: 1 / 3; justify-content: center; gap: 14px; padding: 16px;
    border-top: 0; border-inline-start: 3px solid var(--ink); border-radius: 0; box-shadow: -8px 0 26px rgba(30, 20, 60, .22);
  }
}
@media (min-width: 700px) {
  .logo { font-size: 30px; }
  .logo span { width: 40px; height: 44px; }
  .round { width: 52px; height: 52px; }
  .panel { grid-template-columns: 72px 1fr auto; grid-template-rows: auto; width: min(620px, calc(100% - 32px)); }
  .thumb { grid-row: auto; width: 72px; height: 72px; }
  .pname { font-size: 24px; }
  .cr-tabs, .cr-opts { width: min(640px, 100%); align-self: center; }
  .cr-tab { height: 54px; font-size: 25px; }
  .cr-opts { min-height: 196px; }
  .cr-tile { flex-basis: 84px; }
  .cr-sw { width: 46px; height: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  .hint, .btn, .panel, .sheet, .btn::after, .creator, .creator.leaving { animation: none; }
}
[dir="rtl"] .btn [data-ic] svg { transform: scaleX(-1); }
[dir="rtl"] #crDone [data-ic] svg { transform: none; }
