:root {
  --bg: #13110e;
  --bg-2: #1b1813;
  --panel: #221e18;
  --panel-2: #2a251d;
  --line: #3b342a;
  --text: #efe6d2;
  --muted: #a6997f;
  --gold: #e0b44c;
  --gold-dim: #9c7a2c;
  --green: #2f9e44;
  --green-hi: #69db7c;
  --amber: #f59f00;
  --red: #e03131;
  --team: var(--gold);
  --radius: 10px;
  --hexclip: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at top, #231d15 0%, var(--bg) 60%) fixed var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--gold); }
h1, h2, h3, .brand { font-family: Cinzel, Georgia, serif; letter-spacing: .02em; }
h1, h2, h3 { margin: 0 0 .5em; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

/* ------------------------------------------------------------------ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  padding: .55em 1em; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; text-decoration: none; color: var(--text);
  white-space: nowrap; transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: var(--gold-dim); background: #332c22; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a1408; font-weight: 600; }
.btn.primary:hover { background: #f0c65e; }
.btn.good { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn.good:hover { background: #37b24d; }
.btn.bad { background: #8f2424; border-color: #a83232; color: #fff; }
.btn.bad:hover { background: #b02a2a; }
.btn.ghost { background: transparent; }
.btn.small { padding: .3em .65em; font-size: .88em; }

input[type=text], input[type=password], input[type=url], input[type=number], select, textarea {
  width: 100%; padding: .6em .75em; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-2); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold-dim); box-shadow: 0 0 0 3px #e0b44c22; }
textarea { resize: vertical; min-height: 5em; }
input[type=color] { width: 3.2em; height: 2.4em; padding: 2px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-2); }
label { display: block; font-size: .85em; color: var(--muted); margin: .8em 0 .3em; }
.field-row { display: flex; gap: .8em; flex-wrap: wrap; align-items: end; }
.field-row > * { flex: 1 1 10em; }
.muted { color: var(--muted); }
.error-text { color: #ff8787; }
.hidden { display: none !important; }

.pill { display: inline-block; padding: .15em .6em; border-radius: 99px; font-size: .8em; font-weight: 600; background: var(--panel-2); border: 1px solid var(--line); }
.pill.setup { color: var(--muted); }
.pill.running { color: #1a1408; background: var(--green-hi); border-color: var(--green-hi); }
.pill.ended { color: #fff; background: #5c5346; }
.pill.pending { color: #1a1408; background: var(--amber); border-color: var(--amber); }
.pill.approved { color: #fff; background: var(--green); border-color: var(--green); }
.pill.super { color: #1a1408; background: var(--gold); border-color: var(--gold); font-size: .7em; vertical-align: middle; }
.pill.denied { color: #fff; background: #a83232; border-color: #a83232; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1em 1.2em; }

/* -------------------------------------------------------------------- login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card .hexmark { width: 74px; height: 84px; margin: 0 auto 12px; clip-path: var(--hexclip); background: linear-gradient(160deg, var(--gold), var(--gold-dim)); display: grid; place-items: center; color: #1a1408; font: 700 30px Cinzel, serif; }
.login-card h1 { font-size: 1.7em; }
.login-card form { text-align: left; }
.login-card .btn { width: 100%; margin-top: 1.1em; }

/* --------------------------------------------------------------- team layout */
.app { height: 100%; display: flex; flex-direction: column; }
.team-header { flex: none; background: #17140f; border-bottom: 2px solid var(--team); }
.team-banner { display: block; width: 100%; height: auto; max-height: 22vh; object-fit: cover; }
.team-title { padding: 10px 16px; text-align: center; }
.team-title .name { font: 700 1.5em/1.2 Cinzel, serif; color: var(--team); overflow-wrap: anywhere; }
.team-title .event { font-size: .9em; color: var(--muted); }
.team-body { flex: 1; min-height: 0; display: flex; }
.team-side {
  flex: none; width: 200px; padding: 16px 12px; display: flex; flex-direction: column; gap: 8px;
  background: #17140f; border-right: 1px solid var(--line);
}
.team-side .btn, .team-side form { width: 100%; }
.prize-box { padding: 10px; border: 1px solid var(--gold-dim); border-radius: var(--radius); background: #e0b44c12; }
.btn.prize { width: 100%; background: transparent; border-color: var(--gold); color: var(--gold); font-weight: 700; animation: prizeglow 2s ease-in-out infinite; }
.btn.prize:hover { background: #e0b44c22; }
body.prize-mode .btn.prize { animation: none; background: var(--gold); color: #1a1408; }
@keyframes prizeglow { 50% { box-shadow: 0 0 0 4px #e0b44c33; } }
.prize-hint { margin: .5em 0 0; font-size: .78em; color: var(--muted); text-align: center; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin: 10px 2px 0; font-size: .78em; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; border: 2px solid var(--c); flex: none; }
.board-col { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.xp-bar { flex: none; border-top: 1px solid var(--line); background: #17140f; padding: 8px 16px 10px; }
.xp-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.xp-head .xp-title { font-weight: 700; color: var(--cat-xp); }
.xp-head .xp-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: .85em; }
.xp-list { display: flex; gap: 10px; overflow-x: auto; margin-top: 8px; padding-bottom: 2px; }
.xp-item { flex: 0 0 220px; max-width: 100%; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--cat-xp); border-radius: 8px; padding: 6px 10px; }
.xp-item.done { border-left-color: var(--green-hi); }
.xp-item .name { font-size: .85em; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xp-item .nums { font-size: .75em; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; margin: 2px 0 4px; }
.xp-progress { height: 7px; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.xp-progress > div { height: 100%; width: 0; background: var(--cat-xp); border-radius: 99px; transition: width .5s ease; }
.xp-item.done .xp-progress > div { background: var(--green-hi); }
.xp-empty { font-size: .85em; color: var(--muted); margin-top: 6px; }
.xp-running .xp-progress > div { background-image: linear-gradient(90deg, transparent, #fff3, transparent); background-size: 200% 100%; }
.team-stats { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.team-stats h3 { font-size: .95em; margin-bottom: .6em; color: var(--team); }
.team-stats .progress { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.team-stats .progress-fill { height: 100%; width: 0; background: var(--green-hi); border-radius: 99px; transition: width .4s ease; }
.team-stats .progress-label { font-size: .78em; margin: .35em 0 .6em; }
.team-stats dl { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.team-stats .stat { display: flex; justify-content: space-between; align-items: center; font-size: .88em; padding: 3px 0; }
.team-stats dt { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.team-stats dt .icon { width: 1.2em; text-align: center; }
.team-stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.team-stats .good dd { color: var(--green-hi); }
.team-stats .wait dd { color: var(--amber); }
.team-stats .prize dd, .team-stats .prize dt { color: var(--gold); }
.team-stats .dim dd { color: var(--muted); }
.team-side form { margin-top: auto; }
.board-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; }
.board { position: absolute; inset: 0; overflow: hidden; }
.board.scrolls { overflow: auto; }
.board-canvas { position: relative; }
.notice {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: #1c1811ee; border: 1px solid var(--gold-dim); border-radius: 99px;
  padding: .5em 1.2em; font-weight: 600; box-shadow: 0 6px 24px #0008; text-align: center;
  max-width: calc(100% - 32px); pointer-events: none;
}
.notice.prize { border-color: var(--gold); color: var(--gold); }

/* --------------------------------------------------------------------- hexes */
.hex { position: absolute; transition: transform .15s ease; }
/* Tiles are flat by default; a 3D transform only exists while one is mid-flip.
   (Persistent 3D on every tile blew Chrome's GPU layer budget on larger grids.) */
.hex .flipper { position: relative; width: 100%; height: 100%; }
.hex .face { position: absolute; inset: 0; clip-path: var(--hexclip); background: var(--edge, #4a3f2e); }
.hex .face::before { content: ""; position: absolute; inset: var(--bw, 3px); clip-path: var(--hexclip); background: var(--fill, #2a241c); }
.hex .back, .hex.flipped .front { display: none; }
.hex.flipped .back { display: block; }
.hex.flip-out .flipper { animation: flip-out .32s ease-in forwards; }
.hex.flip-in .flipper { animation: flip-in .38s ease-out; }
@keyframes flip-out { from { transform: perspective(700px) rotateY(0); } to { transform: perspective(700px) rotateY(90deg); } }
@keyframes flip-in { from { transform: perspective(700px) rotateY(-90deg); } to { transform: perspective(700px) rotateY(0); } }
.hex .inner {
  position: absolute; inset: 20% 11%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 4%; overflow: hidden;
}
.hex .front { --fill: linear-gradient(160deg, #2e271e, #1d1913); --edge: #4d412f; }
.hex .glyph { font: 700 calc(var(--s) * .42) Cinzel, serif; color: #5b4d38; line-height: 1; }
.hex .title {
  font-size: calc(var(--s) * .17); line-height: 1.15; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word;
}
.hex .thumb { max-height: 38%; max-width: 60%; object-fit: contain; flex: none; }
.hex .thumb[src=""], .hex .thumb:not([src]) { display: none; }
.hex .badge { position: absolute; left: 50%; bottom: 7%; transform: translateX(-50%); font-size: calc(var(--s) * .2); line-height: 1; }

/* Tile categories tint the outline of flipped tiles. */
:root { --cat-pvm: #ff6b6b; --cat-skilling: #38d9a9; --cat-other: #b197fc; --cat-xp: #4dabf7; }
.hex.cat-pvm { --cat: var(--cat-pvm); }
.hex.cat-skilling { --cat: var(--cat-skilling); }
.hex.cat-other { --cat: var(--cat-other); }
.hex.cat-xp { --cat: var(--cat-xp); }
.hex .cat { font-size: calc(var(--s) * .1); line-height: 1; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--cat, var(--muted)); flex: none; }
.hex .cat:empty { display: none; }
.hex.state-completed .cat { color: #fff; opacity: .85; }
.hex .back { --fill: linear-gradient(160deg, #3a3226, #282219); --edge: var(--cat, var(--team)); }
.hex.state-pending .back { --edge: var(--amber); --fill: linear-gradient(160deg, #3d3220, #2a2216); }
.hex.state-completed .back { --edge: var(--green-hi); --fill: linear-gradient(160deg, #37b24d, #2b8a3e); }
.hex.state-completed .title { color: #fff; text-shadow: 0 1px 2px #0006; }
.hex.denied .back { --fill: linear-gradient(160deg, #4a2626, #2e1b1b); }
.hex.empty .title { color: var(--muted); font-style: italic; font-weight: 400; }

.hex.clickable { cursor: pointer; }
.hex.clickable:hover { transform: scale(1.06); z-index: 5; }
.hex .face::after { content: ""; position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.hex.clickable:hover .face::after { opacity: .1; }
.hex.pickable .front { --edge: var(--team); }
.hex.pickable .glyph { color: var(--team); }
.hex.pickable .front::after { background: var(--team); animation: pickpulse 1.6s ease-in-out infinite; }
.hex.pickable:hover .front::after { animation: none; opacity: .25; }
@keyframes pickpulse { 50% { opacity: .16; } }
.hex.selected { transform: scale(1.06); z-index: 6; }
.hex.selected .face { --edge: #fff; }

/* -------------------------------------------------------------------- modals */
.modal-backdrop {
  position: fixed; inset: 0; background: #000b; z-index: 100; display: grid; place-items: center;
  padding: 16px; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--team);
  border-radius: 12px; padding: 1.3em 1.4em; box-shadow: 0 20px 60px #000a;
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: start; gap: 1em; margin-bottom: .6em; }
.modal-head h2 { flex: 1; margin: 0; font-size: 1.35em; }
.modal-close { background: none; border: 0; font-size: 1.6em; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 .2em; }
.modal-actions { display: flex; gap: .6em; justify-content: flex-end; margin-top: 1.2em; flex-wrap: wrap; }
.tile-image { display: block; max-height: 260px; margin: .4em auto 1em; border-radius: 8px; }
.tile-desc { white-space: pre-wrap; }
.callout { padding: .7em .9em; border-radius: 8px; background: var(--bg-2); border: 1px solid var(--line); margin-top: 1em; }
.callout.denied { border-color: #a83232; background: #2a1414; }
.callout.good { border-color: var(--green); background: #14271a; }
.callout.wait { border-color: var(--amber); background: #2a2212; }

.dropzone {
  margin-top: .4em; border: 2px dashed var(--line); border-radius: 10px; padding: 1.4em 1em;
  text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--gold); background: #e0b44c0d; color: var(--text); }
.dropzone kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .35em; font-size: .9em; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: .8em; }
.thumbs .t { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #000; max-width: 100%; }
.thumbs .t img { width: 100%; height: 100%; object-fit: cover; }
.thumbs .t button { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: #000c; cursor: pointer; }

.history { margin-top: 1.2em; }
.history h3 { font-size: 1em; }
.history-item { padding: .6em 0; border-top: 1px solid var(--line); }
.shots { display: flex; gap: 6px; flex-wrap: wrap; margin-top: .4em; }
.shots img { width: 88px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; }

.toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; z-index: 200; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--gold); padding: .7em 1em; border-radius: 8px; box-shadow: 0 8px 30px #0009; max-width: 420px; animation: fade .2s ease; pointer-events: auto; }
.toast.good { border-left-color: var(--green-hi); }
.toast.bad { border-left-color: var(--red); }

.lightbox { position: fixed; inset: 0; z-index: 300; background: #000e; display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-height: calc(100vh - 32px); object-fit: contain; }

/* --------------------------------------------------------------------- admin */
.admin { display: flex; min-height: 100%; }
.side {
  width: 220px; flex: none; background: #17140f; border-right: 1px solid var(--line);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.side .brand { font-size: 1.15em; color: var(--gold); padding: 4px 10px 2px; }
.side .sub { font-size: .8em; color: var(--muted); padding: 0 10px 12px; }
.side a.nav { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
.side a.nav:hover { background: var(--panel); }
.side a.nav.active { background: var(--panel-2); color: var(--gold); }
.side .count { margin-left: auto; background: var(--amber); color: #1a1408; border-radius: 99px; font-size: .75em; font-weight: 700; padding: 0 .55em; }
.side .spacer { flex: 1; }
.side .who { font-size: .82em; color: var(--muted); padding: 8px 10px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }
.main > h1 { font-size: 1.6em; display: flex; align-items: center; gap: .5em; flex-wrap: wrap; }
.main > h1 .btn { font: 600 14px/1.2 Inter, system-ui, sans-serif; letter-spacing: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55em .6em; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8em; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.team-cell { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.team-cell .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.team-cell img { height: 28px; max-width: 70px; object-fit: contain; border-radius: 4px; }

.sub-card { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 16px; border-left: 4px solid var(--c); }
.sub-card .meta { display: flex; flex-direction: column; gap: .35em; }
.sub-card .shots img { width: 120px; height: 84px; }
.sub-card .deny-box { margin-top: .6em; }
.teams-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.team-form { border-top: 4px solid var(--c); }
.team-form .banner-preview { height: 70px; display: flex; align-items: center; justify-content: center; background: var(--bg-2); border-radius: 8px; margin-top: .4em; overflow: hidden; }
.team-form .banner-preview img { max-height: 70px; }
.admin-board { position: relative; height: calc(100vh - 170px); min-height: 420px; background: #0000002e; border: 1px solid var(--line); border-radius: var(--radius); }
.cat-pill { display: inline-block; font-size: .72em; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: .1em .55em; border-radius: 99px; border: 1px solid var(--c); color: var(--c); }
.xp-team { border-top: 4px solid var(--c); }
.xp-team h2 { display: flex; align-items: center; gap: .5em; flex-wrap: wrap; }
.xp-team .xp-team-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; font: 400 .6em Inter, sans-serif; }
.warn-text { color: var(--amber); }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs .btn.active { border-color: var(--gold); color: var(--gold); }
.audit-action { font-family: ui-monospace, monospace; font-size: .85em; color: var(--gold); white-space: nowrap; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
details.card summary { cursor: pointer; font-weight: 600; }

@media (max-width: 800px) {
  .admin { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 16px; }
  .side .sub, .side .spacer, .side .who { display: none; }
  .main { padding: 16px; }
  .sub-card { grid-template-columns: 1fr; }
  .team-body { flex-direction: column; }
  .team-side { width: auto; flex-direction: row; padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .team-side form { margin-top: 0; width: auto; }
  .team-side { flex-wrap: wrap; }
  .team-side > .btn { flex: 1; }
  .prize-box { order: 2; flex-basis: 100%; padding: 6px; }
  .legend { display: none; }
  .xp-item { flex-basis: 170px; }
  .xp-bar { padding: 6px 12px 8px; }
  .prize-hint { display: none; }
  .team-stats { order: 3; flex-basis: 100%; margin-top: 0; padding: 8px 10px; }
  .team-stats h3, .team-stats .progress-label { display: none; }
  .team-stats dl { flex-direction: row; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
  .team-stats .stat { gap: 6px; padding: 0; }
  .team-title { padding: 8px 16px; }
  .team-title .name { font-size: 1.2em; }
  .team-banner { max-height: 16vh; }
}
