/* INAST Sortier-Challenge – Styles (Spieler, TV, Admin) */

@font-face { font-family: 'Archivo'; src: url('../fonts/archivo-regular.ttf') format('truetype'); font-weight: 400; }
@font-face { font-family: 'Archivo'; src: url('../fonts/archivo-bold.ttf') format('truetype'); font-weight: 700; }
@font-face { font-family: 'Archivo'; src: url('../fonts/archivo-black.ttf') format('truetype'); font-weight: 900; }

:root {
  --orange: #ed700e;
  --orange-dark: #a53500;
  --orange-light: #ffac6b;
  --black: #0c0c0c;
  --grey: #606060;
  --grey-light: #e5e5e5;
  --grey-bg: #f3f3f3;
  --white: #ffffff;
  --green: #2f9e3a;
  --red: #bd0000;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Archivo', system-ui, sans-serif;
  color: var(--black);
  background: var(--white);
}

body.player, body.tv {
  overflow: hidden;
  position: fixed;
  inset: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-weight: 900; letter-spacing: -.02em; margin: 0; line-height: 1.05; }
h1 { font-size: clamp(2.2rem, 6vw, 4rem); }
h2 { font-size: clamp(1.8rem, 5vw, 3rem); }
p { margin: 0; }
.lead { font-size: clamp(1.1rem, 2.4vw, 1.5rem); color: var(--grey); }
.hint { font-size: 1rem; color: var(--grey); max-width: 34em; }
.status { min-height: 1.5em; color: var(--grey); font-size: 1.05rem; }
.status.error { color: var(--red); font-weight: 700; }

/* ---------- Buttons */
.btn {
  font: inherit;
  font-weight: 700;
  border: 3px solid transparent;
  border-radius: 999px;
  padding: .8em 1.8em;
  font-size: 1.15rem;
  cursor: pointer;
  background: var(--grey-light);
  color: var(--black);
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--orange); color: var(--white); }
.btn-primary:not(:disabled):active { background: var(--orange-dark); }
.btn-ghost { background: transparent; border-color: var(--grey-light); }
.btn-big { font-size: clamp(1.3rem, 3vw, 1.9rem); padding: .75em 2.2em; }
.btn-small { font-size: .95rem; padding: .5em 1.1em; }
.btn-danger { background: var(--red); color: var(--white); }

/* ---------- Layout */
.topbar {
  position: absolute;
  top: var(--safe-top); left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px;
  z-index: 5;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar .logo { height: 44px; }

.screen { display: none; position: absolute; inset: 0; padding-top: calc(var(--safe-top) + 70px); padding-bottom: var(--safe-bottom); }
.screen.active { display: flex; flex-direction: column; }

.center {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 16px 24px;
}
.stack > * + * { margin-top: clamp(14px, 2.5vh, 28px); }
.row { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }

/* ---------- Altersklassen-Auswahl */
.levels { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; }
.level {
  width: clamp(200px, 30vw, 300px);
  padding: 22px 16px;
  border-radius: var(--radius);
  border: 4px solid var(--grey-light);
  background: var(--white);
  cursor: pointer;
  transition: transform .1s, border-color .15s, box-shadow .15s;
}
.level:active { transform: scale(.97); }
.level .level-emoji { font-size: 3.4rem; line-height: 1; }
.level .level-name { font-weight: 900; font-size: 1.5rem; margin-top: 8px; }
.level .level-sub { color: var(--grey); margin-top: 2px; }
.level.selected { border-color: var(--orange); box-shadow: 0 0 0 6px rgba(237, 112, 14, .18); }

/* ---------- Lobby */
.ring {
  width: 150px; height: 150px; border-radius: 50%;
  border: 10px solid var(--orange);
  display: grid; place-items: center;
  font-size: 4rem; font-weight: 900;
}
.players { list-style: none; padding: 0; margin: 0; display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.players li {
  background: var(--grey-bg); border-radius: 999px; padding: 10px 20px; font-weight: 700; font-size: 1.15rem;
}
.players li.me { background: var(--orange); color: var(--white); }
.players li small { font-weight: 400; opacity: .8; }

.countdown { font-size: clamp(8rem, 30vh, 18rem); font-weight: 900; color: var(--orange); line-height: 1; animation: pop .9s ease-out infinite; }
@keyframes pop { 0% { transform: scale(.7); opacity: .3; } 30% { transform: scale(1.05); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

/* ---------- Spiel */
#screen-play { padding-top: calc(var(--safe-top) + 8px); }
#screen-play .topbar-hidden { display: none; }

.hud {
  display: grid; grid-template-columns: 1fr 2fr 1fr; align-items: center;
  padding: 10px 24px;
  gap: 12px;
}
.hud-left, .hud-right { display: flex; flex-direction: column; line-height: 1.1; }
.hud-left { align-items: flex-start; }
.hud-right { align-items: flex-end; }
.hud-left span { font-weight: 900; font-size: 1.3rem; }
.hud-left small, .hud-right small { color: var(--grey); }
#hud-score { font-weight: 900; font-size: 2.4rem; color: var(--orange); transition: transform .15s; }
#hud-score.bump { transform: scale(1.3); }
.hud-center { display: flex; align-items: center; gap: 14px; }
.timebar { flex: 1; height: 18px; background: var(--grey-light); border-radius: 999px; overflow: hidden; }
#timebar-fill { height: 100%; width: 100%; background: var(--orange); border-radius: 999px; transition: width .25s linear, background .3s; }
#timebar-fill.low { background: var(--red); }
#hud-time { font-weight: 900; font-size: 1.8rem; min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }

.arena { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
.arena-hint { position: absolute; bottom: 6px; color: var(--grey); font-size: .95rem; opacity: .8; }

.item {
  width: min(42vw, 36vh, 300px);
  aspect-ratio: 1 / 1.05;
  background: var(--white);
  border-radius: 28px;
  box-shadow: var(--shadow);
  border: 4px solid var(--grey-light);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
  padding: 14px;
  touch-action: none;
  cursor: grab;
  z-index: 3;
  will-change: transform;
}
.item.dragging { box-shadow: 0 24px 50px rgba(0, 0, 0, .28); transition: none; cursor: grabbing; }
.item.enter { animation: itemIn .25s ease-out; }
.item.shake { animation: shake .4s; }
.item.drop { animation: itemDrop .25s ease-in forwards; }
.item-visual { font-size: min(22vw, 20vh, 150px); line-height: 1; }
.item-visual img { width: min(30vw, 26vh, 200px); height: min(30vw, 26vh, 200px); object-fit: contain; pointer-events: none; }
.item-name { font-weight: 900; font-size: clamp(1.1rem, 2.6vw, 1.7rem); text-align: center; line-height: 1.1; }
@keyframes itemIn { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes itemDrop { to { transform: scale(.2); opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-14px); } 40% { transform: translateX(12px); } 60% { transform: translateX(-8px); } 80% { transform: translateX(6px); } }

.feedback {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  background: rgba(12, 12, 12, .92); color: var(--white);
  border-radius: var(--radius); padding: 18px 28px;
  max-width: min(80vw, 560px); text-align: center;
  font-size: 1.1rem; line-height: 1.3;
  opacity: 0; pointer-events: none; transition: opacity .15s;
  z-index: 10;
}
.feedback.show { opacity: 1; }
.feedback.show ~ .arena-hint { opacity: 0; }
.feedback strong { display: block; font-size: 1.4rem; margin-bottom: 2px; }
.feedback small { display: block; opacity: .8; font-size: .95rem; margin-top: 2px; }
.feedback.ok strong { color: #8ae07a; }
.feedback.bad strong { color: #ff8a80; }

.bins {
  display: flex; justify-content: center; align-items: flex-end; gap: clamp(6px, 1.2vw, 18px);
  padding: 8px 12px calc(var(--safe-bottom) + 12px);
  background: linear-gradient(to top, var(--grey-bg), transparent);
}
.bin {
  flex: 1 1 0; max-width: 170px; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 4px 8px;
  border-radius: var(--radius);
  border: 4px solid transparent;
  transition: transform .12s, border-color .12s, background .12s;
  cursor: pointer;
}
.bin img { height: min(22vh, 150px); max-width: 100%; object-fit: contain; pointer-events: none; }
.bin-label {
  font-weight: 900; font-size: clamp(.8rem, 1.5vw, 1.05rem); text-align: center; line-height: 1.1;
  color: var(--bin-text, var(--white)); background: var(--bin-color, var(--grey));
  padding: 5px 10px; border-radius: 999px; max-width: 100%;
}
.bin.hover { transform: scale(1.1) translateY(-6px); border-color: var(--orange); background: rgba(237, 112, 14, .08); }
.bin.ok { animation: binOk .5s; }
.bin.bad { animation: binBad .5s; }
@keyframes binOk { 0% { background: rgba(47, 158, 58, .35); transform: scale(1.12); } 100% { background: transparent; transform: scale(1); } }
@keyframes binBad { 0% { background: rgba(189, 0, 0, .3); } 100% { background: transparent; } }

.float {
  position: absolute; font-weight: 900; font-size: 2.2rem; pointer-events: none; z-index: 6;
  animation: floatUp .9s ease-out forwards;
}
.float.plus { color: var(--green); }
.float.minus { color: var(--red); }
@keyframes floatUp { from { transform: translate(-50%, 0); opacity: 1; } to { transform: translate(-50%, -90px); opacity: 0; } }

/* ---------- Ergebnis */
.scorebox { background: var(--grey-bg); border-radius: var(--radius); padding: 22px 44px; }
.scorebox-score { font-size: clamp(2rem, 6vw, 3.4rem); font-weight: 900; color: var(--orange); }
.scorebox-detail { color: var(--grey); font-size: 1.2rem; margin-top: 4px; }
input#nickname {
  font: inherit; font-size: 1.6rem; font-weight: 700; text-align: center;
  padding: .5em .8em; width: min(90vw, 420px);
  border: 4px solid var(--grey-light); border-radius: var(--radius); outline: none;
  -webkit-user-select: text; user-select: text;
}
input#nickname:focus { border-color: var(--orange); }

.highscore { list-style: none; margin: 0; padding: 0; width: min(92vw, 560px); counter-reset: hs; }
.highscore li {
  counter-increment: hs;
  display: grid; grid-template-columns: 2.2em 1fr auto; align-items: center; gap: 12px;
  padding: 8px 14px; border-radius: 12px; font-size: 1.15rem;
}
.highscore li::before { content: counter(hs) '.'; font-weight: 900; color: var(--grey); text-align: right; }
.highscore li:nth-child(odd) { background: var(--grey-bg); }
.highscore li.me { background: var(--orange); color: var(--white); }
.highscore li.me::before { color: var(--white); }
.highscore .hs-name { font-weight: 700; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.highscore .hs-score { font-weight: 900; font-variant-numeric: tabular-nums; }

/* ---------- Hochformat: Tonnen etwas kleiner */
@media (orientation: portrait) {
  .bin img { height: min(16vh, 130px); }
  .item { width: min(60vw, 32vh, 300px); }
  .hud { grid-template-columns: 1fr 1fr; }
  .hud-center { grid-column: 1 / -1; order: 3; }
}

/* ---------- Footer "Entwickelt von" (dezent) */
.credit {
  position: fixed;
  left: 0; right: 0; bottom: calc(var(--safe-bottom) + 10px);
  display: flex; justify-content: center; align-items: center; gap: 7px;
  font-size: .72rem; color: var(--grey); opacity: .55;
  pointer-events: none;
  z-index: 4;
}
.credit img { height: 15px; }
.credit a { pointer-events: auto; display: inline-flex; }
body:has(#screen-play.active) .credit { display: none; }   /* nicht während des Spiels */
.tv .credit { justify-content: flex-end; right: 24px; bottom: 16px; color: rgba(255, 255, 255, .55); opacity: .5; }
.admin .credit { position: static; margin-top: 32px; opacity: .7; }

/* ======================================================= TV */
body.tv {
  background: radial-gradient(ellipse at top, #1e1e1e, #0c0c0c 70%);
  color: var(--white);
  cursor: none;
}
.tv .topbar .logo { height: 56px; }
.tv .tv-title { font-size: clamp(1.4rem, 3vw, 2.4rem); font-weight: 900; letter-spacing: .06em; text-transform: uppercase; color: var(--orange); }
.tv-main { position: absolute; inset: 0; padding: calc(var(--safe-top) + 110px) 60px 50px; display: flex; flex-direction: column; }
.tv-view { display: none; flex: 1; flex-direction: column; min-height: 0; }
.tv-view.active { display: flex; }

.tv-boards { display: grid; grid-template-columns: 1fr 1fr; gap: 50px; flex: 1; min-height: 0; }
.tv-board { background: rgba(255, 255, 255, .06); border-radius: 28px; padding: 28px 34px; display: flex; flex-direction: column; min-height: 0; }
.tv-board h2 { font-size: clamp(1.6rem, 3.2vw, 2.8rem); color: var(--orange); display: flex; align-items: center; gap: 14px; }
.tv-board h2 small { font-size: .5em; color: rgba(255, 255, 255, .55); font-weight: 400; }
.tv-board ol { list-style: none; margin: 18px 0 0; padding: 0; counter-reset: hs; flex: 1; overflow: hidden; }
.tv-board li {
  counter-increment: hs;
  display: grid; grid-template-columns: 2.4em 1fr auto; align-items: center; gap: 16px;
  padding: 9px 16px; border-radius: 14px;
  font-size: clamp(1.1rem, 2.1vw, 1.8rem);
}
.tv-board li::before { content: counter(hs); font-weight: 900; color: rgba(255, 255, 255, .45); text-align: right; }
.tv-board li:nth-child(1)::before { content: '🥇'; }
.tv-board li:nth-child(2)::before { content: '🥈'; }
.tv-board li:nth-child(3)::before { content: '🥉'; }
.tv-board li:nth-child(odd) { background: rgba(255, 255, 255, .05); }
.tv-board li.recent { background: var(--orange); color: var(--white); animation: glow 1.2s ease-in-out infinite alternate; }
.tv-board li.recent::before { color: var(--white); }
@keyframes glow { from { box-shadow: 0 0 0 rgba(237, 112, 14, 0); } to { box-shadow: 0 0 30px rgba(237, 112, 14, .8); } }
.tv-board .hs-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-board .hs-score { font-weight: 900; font-variant-numeric: tabular-nums; }
.tv-board .empty { color: rgba(255, 255, 255, .4); padding: 20px 16px; font-size: 1.3rem; }

.tv-footer { text-align: center; color: rgba(255, 255, 255, .5); font-size: 1.2rem; padding-top: 24px; }

.tv-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 28px; }
.tv-center h1 { font-size: clamp(2.5rem, 6vw, 5.5rem); }
.tv-center .big { font-size: clamp(6rem, 22vh, 16rem); font-weight: 900; color: var(--orange); line-height: 1; font-variant-numeric: tabular-nums; }
.tv-center .lead { color: rgba(255, 255, 255, .7); font-size: clamp(1.4rem, 3vw, 2.4rem); }

.tv-players { display: flex; gap: 36px; justify-content: center; flex-wrap: wrap; width: 100%; }
.tv-player {
  flex: 1 1 260px; max-width: 460px;
  background: rgba(255, 255, 255, .07); border-radius: 28px; padding: 30px 26px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 4px solid transparent;
}
.tv-player.leader { border-color: var(--orange); }
.tv-player .tp-name { font-weight: 900; font-size: clamp(1.4rem, 2.8vw, 2.4rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tv-player .tp-level { color: rgba(255, 255, 255, .6); font-size: 1.2rem; }
.tv-player .tp-score { font-size: clamp(3.5rem, 10vh, 7rem); font-weight: 900; color: var(--orange); line-height: 1.1; font-variant-numeric: tabular-nums; }
.tv-player .tp-detail { color: rgba(255, 255, 255, .6); font-size: 1.2rem; }
.tv-player .tp-rank { margin-top: 10px; font-weight: 700; font-size: 1.3rem; color: #ffd27a; }
.tv-player .tp-rank.pending { color: rgba(255, 255, 255, .45); font-weight: 400; }

/* Logo-Einblendung zwischen den Spielen */
#tv-brand.active { animation: brandIn .8s ease-out; }
.tv-brand-logo { width: min(50vw, 720px); animation: brandFloat 8s ease-in-out infinite alternate; }
@keyframes brandIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes brandFloat { from { transform: scale(1); } to { transform: scale(1.06); } }

.tv-timebar { width: min(80vw, 1100px); height: 26px; background: rgba(255, 255, 255, .12); border-radius: 999px; overflow: hidden; }
.tv-timebar div { height: 100%; width: 100%; background: var(--orange); border-radius: 999px; transition: width .5s linear; }

/* ======================================================= Admin */
body.admin { background: var(--grey-bg); padding: 24px; font-size: 15px; }
.admin main { max-width: 1400px; margin: 0 auto; }
.admin header { display: flex; align-items: center; gap: 24px; margin-bottom: 24px; flex-wrap: wrap; }
.admin header .logo { height: 44px; }
.admin h1 { font-size: 1.8rem; }
.admin h2 { font-size: 1.3rem; margin: 32px 0 12px; }
.admin .card { background: var(--white); border-radius: var(--radius); padding: 20px 24px; box-shadow: 0 2px 10px rgba(0, 0, 0, .06); }
.admin .table-wrap { overflow-x: auto; }
.admin table { width: 100%; min-width: 1100px; border-collapse: collapse; }
.admin th, .admin td { padding: 6px 6px; border-bottom: 1px solid var(--grey-light); text-align: left; vertical-align: middle; }
.admin th { font-size: .85rem; color: var(--grey); text-transform: uppercase; letter-spacing: .04em; }
.admin input[type="text"], .admin select, .admin input[type="number"] {
  font: inherit; padding: 6px 8px; border: 2px solid var(--grey-light); border-radius: 8px; width: 100%; background: var(--white);
}
.admin input:focus, .admin select:focus { outline: none; border-color: var(--orange); }
.admin td.emoji input { width: 3.2em; font-size: 1.3rem; text-align: center; }
.admin td.id input { width: 11em; font-family: ui-monospace, monospace; font-size: .9rem; }
.admin td.name input { min-width: 14em; }
.admin td.bild input { min-width: 10em; font-family: ui-monospace, monospace; font-size: .85rem; }
.admin td.levels { white-space: nowrap; }
.admin td.levels label { white-space: nowrap; }
.admin select { min-width: 11em; }
.admin td.levels label { margin-right: 10px; }
.admin td.info input { min-width: 22em; }
.admin td.actions { white-space: nowrap; }
.admin tr.invalid { background: #fff3f3; }
.admin .toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 16px 0; }
.admin .toolbar .spacer { flex: 1; }
.admin .msg { font-weight: 700; }
.admin .msg.ok { color: var(--green); }
.admin .msg.error { color: var(--red); }
.admin .settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.admin .settings label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; }
.admin .settings small { font-weight: 400; color: var(--grey); }
.admin .links a { color: var(--orange-dark); font-weight: 700; margin-right: 18px; }
.admin code { background: var(--grey-light); padding: 2px 6px; border-radius: 6px; }
.admin .preview img { height: 1.8em; vertical-align: middle; }

/* ======================================================= Startseite (Spiel / Anzeige) */
body.landing { touch-action: auto; }
.choices { display: flex; gap: 28px; flex-wrap: wrap; justify-content: center; }
.choice {
  width: clamp(240px, 34vw, 360px);
  padding: 34px 20px 28px;
  border-radius: var(--radius);
  border: 4px solid var(--grey-light);
  background: var(--white);
  color: var(--black);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform .1s, border-color .15s;
}
.choice:hover, .choice:focus-visible { border-color: var(--orange); outline: none; }
.choice:active { transform: scale(.97); }
.choice-emoji { font-size: 4.5rem; line-height: 1; }
.choice-name { font-weight: 900; font-size: 2rem; margin-top: 12px; }
.choice-sub { color: var(--grey); margin-top: 4px; }
.admin-link { color: var(--grey); text-decoration: underline; }
