:root {
  --bg: #cdcdcd;
  --grid: #c3c3c3;
  --ink: #555555;
  --ink-dark: #3c3c3c;
  --panel: #e8e8e8;
  --blue: #00b2e1;   --blue-d: #0085a8;
  --red: #f14e54;    --red-d: #b4393f;
  --yellow: #ffe869; --yellow-d: #bfae4e;
  --green: #00e16e;  --green-d: #00a852;
  --purple: #768dfc; --purple-d: #5868bd;
  --pink: #f177dd;   --pink-d: #b459a6;
  --grey: #999999;   --grey-d: #727272;
  --outline: 4px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink-dark);
  font-family: 'Ubuntu', system-ui, sans-serif;
  font-weight: 700;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
[hidden] { display: none !important; }

#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }

.screen {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px 24px;
}

/* diep-style outlined text */
.stroke, .logo, .btn, .code, .vs {
  color: #fff;
  -webkit-text-stroke: 0.22em var(--ink-dark);
  paint-order: stroke fill;
}

.logo {
  font-size: clamp(64px, 16vw, 120px);
  margin: 12px 0 0;
  letter-spacing: -0.02em;
  line-height: 1;
  -webkit-text-stroke-width: 0.14em;
  animation: pop-in 0.5s cubic-bezier(.3,1.6,.5,1) both;
}
.logo .l1 { color: var(--blue); }
.logo .lv { color: #fff; font-size: 0.7em; margin: 0 0.04em; }
.logo .l2 { color: var(--red); }
.logo .tld { color: #fff; font-size: 0.42em; margin-left: 0.06em; }

.tagline { margin: 10px 0 24px; color: var(--ink); font-weight: 500; text-align: center; }

.panel {
  background: var(--panel);
  border: var(--outline) solid var(--ink);
  border-radius: 12px;
  padding: 16px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.12);
}

.label { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink); margin-bottom: 8px; }

input {
  width: 100%;
  font: inherit;
  font-size: 22px;
  color: var(--ink-dark);
  background: #fff;
  border: var(--outline) solid var(--ink);
  border-radius: 8px;
  padding: 10px 14px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
input:focus { border-color: var(--blue-d); }

.join-panel { margin-top: 14px; }
.join-panel.invited { border-color: var(--green-d); animation: pop-in 0.4s cubic-bezier(.3,1.6,.5,1) both; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 0.25em; min-width: 0; }
.join-row input::placeholder { letter-spacing: 0.1em; }
.join-row .btn { flex: none; font-size: 18px; }

.server-label { margin-top: 14px; }
.server-pick, .server-item {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  font: inherit; font-size: 17px; color: var(--ink-dark);
  background: #fff;
  border: var(--outline) solid var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  text-align: left;
}
.server-pick::after { content: ''; margin-left: 4px; border: 6px solid transparent; border-top-color: var(--ink); transform: translateY(3px); }
.server-pick .sname, .server-item .sname { flex: 1; }
.cc {
  font-size: 12px; color: #fff; background: var(--purple); border: 3px solid var(--purple-d);
  border-radius: 6px; padding: 0 6px; -webkit-text-stroke: 0;
}
.ms { font-size: 15px; display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
.ms::before { content: ''; width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--grey-d); background: var(--grey); }
.ms.good::before { background: var(--green); border-color: var(--green-d); }
.ms.ok::before { background: var(--yellow); border-color: var(--yellow-d); }
.ms.bad::before { background: var(--red); border-color: var(--red-d); }
.server-list { margin-top: 8px; display: grid; gap: 6px; animation: pop-in 0.25s cubic-bezier(.3,1.6,.5,1) both; }
.server-item { border-width: 3px; }
.server-item.sel { border-color: var(--blue-d); background: #eaf8fd; }

.btn {
  font: inherit;
  font-size: 20px;
  padding: 10px 22px 14px;
  border: var(--outline) solid var(--ink);
  border-radius: 10px;
  background: var(--c, var(--blue));
  box-shadow: inset 0 -6px 0 rgba(0,0,0,0.2);
  cursor: pointer;
  -webkit-text-stroke-width: 0.2em;
  transition: transform 0.08s, filter 0.12s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px) scale(0.98); box-shadow: inset 0 -3px 0 rgba(0,0,0,0.2); }
.btn.big { font-size: 26px; width: 100%; }
.btn.small { font-size: 15px; padding: 6px 12px 9px; }
.btn-blue { --c: var(--blue); }
.btn-green { --c: var(--green); }
.btn-red { --c: var(--red); }
.btn-grey { --c: var(--grey); }
.btn:disabled { filter: grayscale(1) opacity(0.6); cursor: default; transform: none; }

.games {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 560px;
  margin-top: 24px;
}
/* Wider screens: 3 tiles per row, then 4 on desktop. */
@media (min-width: 760px) { .games { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 780px; gap: 16px; } }
@media (min-width: 1040px) { .games { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 1020px; gap: 18px; } }
.tile {
  position: relative;
  background: var(--panel);
  border: var(--outline) solid var(--ink);
  border-radius: 14px;
  padding: 12px 12px 14px;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 6px 0 rgba(0,0,0,0.12);
  transition: transform 0.15s cubic-bezier(.3,1.6,.5,1);
  animation: pop-in 0.45s cubic-bezier(.3,1.6,.5,1) both;
  font: inherit;
  color: inherit;
}
.tile:hover:not(.soon) { transform: translateY(-4px) rotate(-1deg); }
.tile:active:not(.soon) { transform: translateY(1px) scale(0.98); }
.tile .art {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  border: 3px solid var(--ink);
  background: var(--bg);
  margin-bottom: 10px;
}
.tile .name { font-size: 20px; color: #fff; -webkit-text-stroke: 0.2em var(--ink-dark); paint-order: stroke fill; }
.tile .kind { display: inline-block; margin: 6px 2px 0; font-size: 12px; color: var(--ink); background: #fff; border: 3px solid var(--ink); border-radius: 99px; padding: 1px 9px; }
.tile .cta { display: block; margin-top: 10px; font-size: 15px; }
.tile .cta-row { display: flex; gap: 6px; margin-top: 10px; }
.tile .cta-row .cta { flex: 1; margin-top: 0; padding-left: 4px; padding-right: 4px; }
.tile .record { margin-top: 6px; font-size: 12px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .record:empty { display: none; }
.tile.soon { cursor: default; }
.tile.soon .art { filter: grayscale(0.6) opacity(0.7); }
.tile .badge {
  position: absolute; top: -10px; right: -8px;
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 8px;
  padding: 2px 8px; font-size: 13px; transform: rotate(8deg); color: var(--ink-dark);
}

.foot { margin-top: 28px; font-weight: 500; color: var(--ink); font-size: 14px; }

/* Room */
#room { justify-content: center; }
.room-panel { text-align: center; max-width: 440px; animation: pop-in 0.4s cubic-bezier(.3,1.6,.5,1) both; }
.room-game { font-size: 15px; color: var(--ink); margin-bottom: 12px; }
.code { font-size: 54px; letter-spacing: 0.12em; margin: 0 0 14px; -webkit-text-stroke-width: 0.16em; }
.share { display: flex; gap: 8px; }
.share input { font-size: 15px; padding: 8px 10px; min-width: 0; }
.share .btn { font-size: 16px; padding: 6px 14px 10px; flex: none; }
.hint { color: var(--ink); font-weight: 500; font-size: 14px; margin: 14px 0; }
.slots { display: flex; align-items: center; gap: 10px; margin: 6px 0 18px; }
.slot {
  flex: 1; min-width: 0;
  border: var(--outline) solid var(--ink);
  border-radius: 10px;
  padding: 12px 8px 14px;
  background: #fff;
}
.slot .dot { width: 34px; height: 34px; margin: 0 auto 8px; border-radius: 50%; border: 4px solid; }
.slot .who { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot.empty .who { color: var(--grey); }
.slot.empty .dot { animation: bob 1s ease-in-out infinite; border-style: dashed; background: transparent !important; border-color: var(--grey) !important; }
.slot { position: relative; }
.slot.c0 .dot { background: var(--blue); border-color: var(--blue-d); }
.slot.c1 .dot { background: var(--red); border-color: var(--red-d); }
.slot.c2 .dot { background: var(--purple); border-color: var(--purple-d); }
.slot.c3 .dot { background: var(--yellow); border-color: var(--yellow-d); }
.slots.many { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slots.many .slot { padding: 8px 8px 10px; }
.slots.many .slot .dot { width: 26px; height: 26px; margin-bottom: 4px; }
.crown {
  position: absolute; top: -10px; right: -6px;
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 8px;
  padding: 0 7px; font-size: 12px; color: var(--ink-dark); transform: rotate(8deg);
}
.vs { font-size: 26px; }
.settings { display: grid; gap: 10px; margin: 4px 0 6px; padding: 12px; border: 3px solid var(--ink); border-radius: 10px; background: #fff; text-align: left; }
.setting { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 10px; }
.setting .label { margin: 0; }
.seg { display: flex; gap: 5px; flex-wrap: wrap; }
.seg button {
  font: inherit; font-size: 15px; min-width: 40px; padding: 4px 8px 6px;
  color: var(--ink-dark); background: var(--panel);
  border: 3px solid var(--ink); border-radius: 8px; cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.12);
}
.seg button.sel { background: var(--blue); color: #fff; -webkit-text-stroke: 0.2em var(--ink-dark); paint-order: stroke fill; }
.seg button:disabled { cursor: default; }
.seg button:disabled:not(.sel) { opacity: 0.45; }
#start-btn { margin-bottom: 12px; }
#bot-btn { margin: -6px 0 14px; }
.room-back { margin-top: 2px; }
.wait-host { color: var(--ink); font-weight: 500; margin: 0 0 10px !important; }

/* Play */
#play { padding: 0; height: 100%; overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: none; -webkit-touch-callout: none; }
.leave { position: absolute; top: 12px; left: 12px; z-index: 3; }
.overlay {
  position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(205,205,205,0.55);
}
.overlay .panel { text-align: center; max-width: 360px; animation: pop-in 0.35s cubic-bezier(.3,1.6,.5,1) both; }
.overlay h2 { font-size: 40px; margin: 4px 0 6px; color: #fff; -webkit-text-stroke: 0.2em var(--ink-dark); paint-order: stroke fill; }
.overlay p { color: var(--ink); font-weight: 500; margin: 0 0 16px; }
.overlay .btn + .btn { margin-top: 10px; }
.rank { display: grid; gap: 6px; margin: 0 0 16px; text-align: left; }
.rank-row { display: flex; align-items: center; gap: 10px; background: #fff; border: 3px solid var(--ink); border-radius: 8px; padding: 5px 10px; font-size: 16px; }
.rank-row .rank-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-dot { width: 16px; height: 16px; border-radius: 50%; border: 3px solid; flex: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 10;
  transform: translateX(-50%);
  background: var(--panel); border: var(--outline) solid var(--ink); border-radius: 10px;
  padding: 10px 16px; animation: pop-in 0.3s cubic-bezier(.3,1.6,.5,1) both;
  max-width: calc(100% - 32px);
}

@keyframes pop-in { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bob { 50% { transform: translateY(-5px); } }

@media (max-width: 420px) {
  .games { gap: 10px; }
  .tile .name { font-size: 17px; }
  .code { font-size: 44px; }
}

/* Leaderboards */
.room-board { margin: 14px 0 4px; text-align: left; }
.room-board .label { text-align: center; }
.board { display: grid; gap: 4px; margin: 6px 0 0; }
.board-row { display: flex; align-items: center; gap: 8px; background: #fff; border: 3px solid var(--ink); border-radius: 8px; padding: 3px 10px; font-size: 15px; }
.board-row.me { background: var(--yellow, #ffe869); }
.board-pos { width: 26px; flex: none; color: var(--ink); }
.board-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-score { flex: none; }
.board-empty { color: var(--ink); font-weight: 500; margin: 4px 0 0; text-align: center; }
.overlay .board { margin: 0 0 16px; text-align: left; max-height: 40vh; overflow-y: auto; }

/* Quick match */
.btn-purple { --c: var(--purple); }
.quick-panel { margin-top: 14px; text-align: center; }
.quick-panel .btn { animation: pulse 2.4s ease-in-out infinite; }
.quick-sub { margin: 8px 0 0; color: var(--ink); font-weight: 500; font-size: 14px; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
#quick { justify-content: center; }
.quick-box { text-align: center; max-width: 440px; animation: pop-in 0.4s cubic-bezier(.3,1.6,.5,1) both; overflow: hidden; }
.search-ring { display: flex; justify-content: center; gap: 12px; margin: 18px 0 10px; }
.search-dot { width: 22px; height: 22px; border-radius: 50%; border: 4px solid var(--purple-d); background: var(--purple); animation: bob 0.9s ease-in-out infinite; }
.search-dot:nth-child(2) { animation-delay: 0.15s; background: var(--blue); border-color: var(--blue-d); }
.search-dot:nth-child(3) { animation-delay: 0.3s; background: var(--red); border-color: var(--red-d); }
.search-title { font-size: 30px; margin: 4px 0 14px; }
.search-bar { height: 18px; border: 3px solid var(--ink); border-radius: 99px; background: #fff; overflow: hidden; }
#search-fill { height: 100%; width: 0; background: var(--purple); border-right: 3px solid var(--purple-d); }
.quick-vs { margin: 10px 0 14px; }
.slot .bot-tag {
  position: absolute; top: -12px; right: -8px;
  background: var(--grey); border: 3px solid var(--ink); border-radius: 8px;
  padding: 0 7px; font-size: 12px; color: #fff; transform: rotate(8deg);
  -webkit-text-stroke: 0.2em var(--ink-dark); paint-order: stroke fill;
}
.reel { position: relative; height: 118px; margin: 0 -16px; border-top: var(--outline) solid var(--ink); border-bottom: var(--outline) solid var(--ink); background: var(--bg); overflow: hidden; }
.reel-strip { position: absolute; top: 9px; left: 0; display: flex; gap: 10px; will-change: transform; }
.reel-item { flex: none; width: 112px; height: 92px; border: 3px solid var(--ink); border-radius: 10px; background: var(--panel); padding: 4px; }
.reel-item canvas { display: block; width: 100%; height: 62px; border: 2px solid var(--ink); border-radius: 6px; background: var(--bg); }
.reel-item span { display: block; margin-top: 3px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-dark); }
.reel-item.win { border-color: var(--purple-d); background: #fff; animation: pop-in 0.35s cubic-bezier(.3,1.6,.5,1) both; }
.reel-mark { position: absolute; left: 50%; top: 0; bottom: 0; width: 120px; transform: translateX(-50%); border-left: 4px solid var(--purple-d); border-right: 4px solid var(--purple-d); pointer-events: none; }
.reel-mark::before, .reel-mark::after { content: ''; position: absolute; left: 50%; transform: translateX(-50%); border: 10px solid transparent; }
.reel-mark::before { top: -2px; border-top-color: var(--purple-d); }
.reel-mark::after { bottom: -2px; border-bottom-color: var(--purple-d); }
.reel-name { font-size: 28px; margin: 14px 0 2px; min-height: 36px; }
.reel-name.landed { animation: pop-in 0.4s cubic-bezier(.3,1.6,.5,1) both; }
