:root {
  --red: #d6273e;
  --blue: #1f6fd6;
  --black: #23232b;
  --orange: #e8821e;

  --felt: #0f6b4f;
  --felt-dark: #0a4e3a;
  --wood: #7a4a24;
  --wood-light: #9c6334;
  --tile-face: #f7f1e1;
  --tile-edge: #e4dcc5;

  --ink: #1c2024;
  --panel: #1b2a2e;
  --panel-2: #16373a;
  --txt: #eaf3ee;
  --muted: #9fb7ad;
  --gold: #f4c863;

  --radius: 12px;
  --shadow: 0 6px 18px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--txt);
  background:
    radial-gradient(1200px 700px at 50% -10%, #1d4a3f 0%, #0c2c27 60%, #08201d 100%);
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px 14px 16px;
  gap: 10px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: .5px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px; color: #2a1a00;
  background: linear-gradient(160deg, var(--gold), #d79a2b);
  box-shadow: var(--shadow);
}
.topbar-controls { display: flex; align-items: center; gap: 8px; }
.bots-select {
  font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px;
}
.bots-select select {
  background: var(--panel); color: var(--txt); border: 1px solid #2c4a44;
  border-radius: 8px; padding: 5px 8px; font-size: 13px;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid #2f534c; background: var(--panel); color: var(--txt);
  padding: 12px 18px; border-radius: 10px; font-size: 16px; cursor: pointer;
  min-height: 48px;
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { background: #21413c; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(160deg, #2fae7a, #1c8d5f);
  border-color: #2fae7a; color: #06251a; font-weight: 700; font-size: 17px;
}
.btn-primary:hover { background: linear-gradient(160deg, #38c189, #21a06d); }
.btn-ghost { background: transparent; }
.btn-small { padding: 10px 13px; font-size: 14px; min-height: 44px; }
.spacer { flex: 1; }

/* ---------- Opponents ---------- */
.opponents { display: flex; gap: 10px; flex-wrap: wrap; }
.opp {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid #284743;
  border-radius: 12px; padding: 8px 12px; min-width: 130px;
}
.opp .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(160deg, #3a6b60, #214a42);
  display: grid; place-items: center; font-size: 15px;
}
.opp .opp-name { font-size: 13px; font-weight: 600; }
.opp .opp-sub { font-size: 11px; color: var(--muted); }
.opp.is-turn {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(244, 200, 99, .25);
}
.opp.is-turn .avatar { background: linear-gradient(160deg, var(--gold), #cf9b2e); color: #2a1a00; }
.opp .mini-tiles { display: flex; gap: 2px; }
.mini-tile {
  width: 9px; height: 13px; border-radius: 2px;
  background: linear-gradient(160deg, #caa15f, #9c6334);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
}

/* ---------- Table ---------- */
.table {
  flex: 1;
  min-height: 240px;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.012) 0 10px, transparent 10px 20px),
    radial-gradient(120% 120% at 50% 0%, var(--felt) 0%, var(--felt-dark) 100%);
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, .25);
  box-shadow: inset 0 2px 24px rgba(0, 0, 0, .35);
  padding: 14px;
  overflow: auto;
}
.sets {
  display: flex; flex-wrap: wrap; gap: 12px; align-content: flex-start;
  min-height: 100%;
}
.set {
  display: flex; gap: 3px; align-items: center;
  background: rgba(0, 0, 0, .16);
  border: 1px dashed rgba(255, 255, 255, .14);
  border-radius: 12px; padding: 8px;
  min-height: 76px;
}
.set.invalid {
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(214, 39, 62, .35);
  background: rgba(214, 39, 62, .08);
}
.set.fresh { border-color: rgba(244, 200, 99, .5); }
.set.drop-target { border-color: var(--gold); background: rgba(244, 200, 99, .1); }
.newset-zone {
  display: flex; align-items: center; justify-content: center;
  min-width: 84px; min-height: 84px;
  border: 2px dashed rgba(255, 255, 255, .26); border-radius: 12px;
  color: var(--muted); font-size: 15px; text-align: center; padding: 8px;
}
.newset-zone.drop-target { border-color: var(--gold); color: var(--gold); }
.table-empty-hint {
  color: #cfe6da; font-size: 17px; margin: auto; text-align: center;
  padding: 30px; line-height: 1.6; max-width: 560px;
}

/* ---------- Tiles ---------- */
.tile {
  position: relative;
  width: 50px; height: 68px;
  border-radius: 9px;
  background: linear-gradient(170deg, #fffdf5 0%, var(--tile-face) 55%, var(--tile-edge) 100%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .7), inset 0 -3px 4px rgba(0, 0, 0, .08);
  display: grid; place-items: center;
  cursor: grab; touch-action: none;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.tile .num {
  font-size: 32px; font-weight: 800; line-height: 1;
}
.tile.c-red .num, .tile.c-red .corner { color: var(--red); }
.tile.c-blue .num, .tile.c-blue .corner { color: var(--blue); }
.tile.c-black .num, .tile.c-black .corner { color: var(--black); }
.tile.c-orange .num, .tile.c-orange .corner { color: var(--orange); }
.tile .corner {
  position: absolute; bottom: 4px; right: 5px; font-size: 10px; font-weight: 700; opacity: .55;
}
.tile.joker { background: linear-gradient(170deg, #fffdf5, #f2e9cf); }
.tile.joker .num { font-size: 24px; color: var(--red); }
.tile.joker::after {
  content: "★"; position: absolute; bottom: 3px; right: 4px; font-size: 11px; color: var(--orange);
}
.tile.is-dragging { opacity: .28; }
.tile.hint { animation: pulse 1s ease infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 3px 6px rgba(0,0,0,.3), 0 0 0 0 rgba(244,200,99,.0); }
  50% { box-shadow: 0 3px 6px rgba(0,0,0,.3), 0 0 0 4px rgba(244,200,99,.55); }
}

/* ---------- Status ---------- */
.status {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 40px; padding: 0 4px; flex-wrap: wrap;
}
.status-msg {
  font-size: 17px; font-weight: 600; color: var(--txt);
  padding: 8px 14px; border-radius: 10px;
}
.status-msg.you { background: rgba(47, 174, 122, .18); color: #9af0c4; box-shadow: inset 0 0 0 1px rgba(47, 174, 122, .4); }
.status-msg.bot { background: rgba(244, 200, 99, .14); color: var(--gold); box-shadow: inset 0 0 0 1px rgba(244, 200, 99, .3); }
.status-msg.error { background: rgba(214, 39, 62, .16); color: #ff9aa6; box-shadow: inset 0 0 0 1px rgba(214, 39, 62, .45); }
.status-msg.ok { background: rgba(47, 174, 122, .18); color: #7ff0bd; }
.meld-info { font-size: 15px; color: var(--muted); }
.meld-info b { color: var(--gold); }

/* ---------- Rack ---------- */
.rack-area { padding: 2px; }
.rack {
  display: flex; flex-wrap: wrap; gap: 5px; align-items: center;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.06) 0 2px, transparent 2px 22px),
    linear-gradient(180deg, var(--wood-light), var(--wood));
  border-radius: 14px;
  padding: 12px;
  min-height: 84px;
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, .35), 0 4px 10px rgba(0, 0, 0, .25);
  border: 1px solid #5e3719;
}
.rack.drop-target { box-shadow: inset 0 0 0 2px var(--gold); }

/* ---------- Controls ---------- */
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Log ---------- */
.logwrap { font-size: 13px; }
.logwrap summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.log {
  list-style: none; margin: 6px 0 0; padding: 8px 12px; max-height: 130px; overflow: auto;
  background: rgba(0, 0, 0, .2); border-radius: 10px;
}
.log li { padding: 2px 0; color: var(--muted); border-bottom: 1px solid rgba(255,255,255,.04); }
.log li:last-child { color: var(--txt); }

/* ---------- Drag layer ---------- */
.drag-layer { position: fixed; inset: 0; pointer-events: none; z-index: 1000; }
.drag-layer .tile { position: fixed; box-shadow: 0 12px 24px rgba(0, 0, 0, .45); transform: scale(1.06); }

/* ---------- Overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(4, 16, 13, .72);
  display: grid; place-items: center; z-index: 2000;
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.overlay-card {
  background: linear-gradient(180deg, #173b35, #102b28);
  border: 1px solid #2c544c; border-radius: 18px;
  padding: 26px 28px; max-width: 460px; width: calc(100% - 40px);
  box-shadow: var(--shadow); text-align: center;
}
.overlay-card h2 { margin: 0 0 12px; font-size: 26px; }
.overlay-card #overlayBody { color: #dbe9e2; font-size: 16px; line-height: 1.7; text-align: left; }
.overlay-card #overlayBody h3 { color: var(--gold); font-size: 17px; margin: 16px 0 6px; }
.overlay-card #overlayBody p { margin: 10px 0; }
.overlay-card #overlayBody div { margin: 7px 0; }
.overlay-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.win-badge { font-size: 46px; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .brand h1 { font-size: 18px; }
  .tile { width: 44px; height: 60px; }
  .tile .num { font-size: 28px; }
  .btn { padding: 11px 13px; font-size: 15px; min-height: 46px; }
  .btn-primary { font-size: 16px; }
  .status-msg { font-size: 16px; }
  .controls { gap: 7px; }
}

.thinking { display: inline-flex; gap: 3px; vertical-align: middle; margin-left: 6px; }
.thinking i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--gold);
  animation: blink 1s infinite both;
}
.thinking i:nth-child(2) { animation-delay: .2s; }
.thinking i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- Animationen / Politur ---------- */
@media (hover: hover) {
  .tile { transition: transform .08s ease, box-shadow .12s ease; }
  .rack .tile:hover, .set .tile:hover { transform: translateY(-3px); box-shadow: 0 7px 12px rgba(0, 0, 0, .4); }
}
.overlay:not(.hidden) { animation: overlayIn .2s ease; }
.overlay-card { animation: cardIn .26s cubic-bezier(.2, .9, .3, 1.25); }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(.95); } to { opacity: 1; transform: none; } }
.tile.deal-in { animation: dealIn .36s ease both; }
@keyframes dealIn { from { opacity: 0; transform: translateY(18px) rotate(-5deg); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .overlay:not(.hidden), .overlay-card, .tile.deal-in { animation: none; }
}
