:root {
  color: #f7f3e8;
  background: #101713;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  --strip: 34px;
  --hand: 206px;
  --panel: min(340px, 42vw);
  --ink: #152019;
  --paper: rgba(252, 249, 238, .94);
  --cyan: #4de6ed;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
@supports (height: 100dvh) {
  html, body, #app { height: 100dvh; }
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

#table-shell {
  position: relative;
  width: 100%;
  height: 100%;
  background: #285b43;
  overflow: hidden;
}

#top-strip {
  position: absolute;
  inset: 0 0 auto;
  height: var(--strip);
  background: #101713;
  z-index: 20;
}

.edge-tab {
  position: absolute;
  inset: 0 auto 0 0;
  min-width: 80px;
  border: 0;
  border-radius: 0 0 7px 0;
  padding: 0 16px;
  color: #f7f3e8;
  background: #23362d;
  letter-spacing: .08em;
  font-weight: 800;
}
.edge-tab.right { inset: 0 0 0 auto; border-radius: 0 0 0 7px; }
#log-light {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 7px;
  border-radius: 50%;
  background: #ffd34e;
  opacity: .25;
  box-shadow: 0 0 0 transparent;
}
#log-light.pulse { animation: log-pulse .5s ease-out; }
@keyframes log-pulse {
  0% { opacity: 1; box-shadow: 0 0 12px #ffd34e; }
  100% { opacity: .25; box-shadow: 0 0 0 transparent; }
}

#felt {
  position: absolute;
  inset: var(--strip) 0 var(--hand);
  width: 100%;
  height: calc(100% - var(--strip) - var(--hand));
  display: block;
  background:
    radial-gradient(circle at 50% 25%, rgba(255,255,255,.04), transparent 50%),
    #285b43;
  touch-action: none;
  outline: none;
}

#view-controls {
  position: absolute;
  z-index: 18;
  top: calc(var(--strip) + 10px);
  left: 50%;
  display: flex;
  transform: translateX(-50%);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 22px;
  background: rgba(16, 23, 19, .82);
  box-shadow: 0 5px 16px rgba(0,0,0,.28);
}
#view-controls[hidden] { display: none; }
#view-controls button {
  min-width: 44px;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-right: 1px solid rgba(255,255,255,.18);
  color: #fff;
  background: transparent;
  font-weight: 800;
}
#view-controls button:last-child { border-right: 0; }
#view-controls button:active { background: rgba(255,255,255,.18); }

.overlay-panel {
  position: absolute;
  top: var(--strip);
  bottom: var(--hand);
  z-index: 30;
  width: var(--panel);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.overlay-panel.controls { left: 0; background: rgba(17, 35, 27, .96); }
.overlay-panel.log { right: 0; color: var(--ink); background: rgba(250, 248, 238, .91); }
.overlay-panel > header {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255,255,255,.15);
}
.log > header { border-color: rgba(0,0,0,.12); }
.overlay-panel header button { margin-left: 5px; }
.panel-scroll { height: calc(100% - 48px); overflow: auto; padding: 4px 14px 24px; }
.panel-scroll section { padding: 10px 0 14px; border-bottom: 1px solid rgba(255,255,255,.12); }
h2 { margin: 6px 0 10px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.panel-scroll label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; }
.panel-scroll button, .panel-scroll select, .panel-scroll input { min-height: 32px; }
.panel-scroll section > button { display: block; width: 100%; margin: 6px 0; }
.panel-scroll input[type="number"] { width: 84px; }
.panel-scroll input[type="text"], #player-name { width: 100px; }
.check { justify-content: flex-start !important; }
.button-row { display: flex; gap: 6px; }
.button-row > * { flex: 1; }
.room-code-row {
  margin: 9px 0;
  padding: 9px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px;
  background: rgba(0,0,0,.2);
}
.room-code-row > span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
}
.room-code-row strong {
  color: #ffd65b;
  font: 800 16px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .12em;
}
.room-code-row button { width: 100%; }

#log-scroll {
  height: calc(100% - 48px);
  overflow: auto;
  padding: 10px 12px 24px;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.log-line { padding: 3px 0; border-bottom: 1px solid rgba(0,0,0,.06); }

#table-info {
  position: absolute;
  z-index: 12;
  left: 14px;
  bottom: calc(var(--hand) + 12px);
  color: white;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
  pointer-events: none;
}

#hand-zone {
  position: absolute;
  inset: auto 0 0;
  height: var(--hand);
  z-index: 15;
  background: #17241e;
  border-top: 2px solid rgba(255,255,255,.14);
}
#hand-zone > header {
  height: 36px;
  padding: 5px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.hand-actions { display: flex; align-items: center; gap: 6px; }
.hand-scroll-button { display: none; }
#hand-scroll { height: calc(100% - 36px); overflow-x: auto; overflow-y: hidden; }
#hand-cards {
  position: relative;
  height: 154px;
  min-width: 100%;
  padding: 5px 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.hand-card {
  position: relative;
  flex: 0 0 99px;
  width: 99px;
  height: 139px;
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
  touch-action: none;
}
.hand-card.dragging { opacity: .28; }
.hand-insert {
  flex: 0 0 4px;
  align-self: stretch;
  height: 142px;
  border-radius: 3px;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}
.hand-drag-overlay { transform-origin: center; }
@keyframes hand-wiggle {
  from { transform: translate(-50%, -50%) rotate(-2deg); }
  to { transform: translate(-50%, -50%) rotate(2deg); }
}

#context-menu {
  position: fixed;
  z-index: 100;
  width: max-content;
  min-width: 230px;
  max-width: 350px;
  margin: 0;
  padding: 5px;
  border: 1px solid #78887e;
  border-radius: 7px;
  color: #152019;
  background: #faf8ee;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
#context-menu button {
  display: block;
  width: 100%;
  min-height: 31px;
  padding: 5px 9px;
  border: 0;
  border-radius: 4px;
  text-align: left;
  color: inherit;
  background: transparent;
}
#context-menu button:hover:not(:disabled) { background: #d7eee3; }
#context-menu button:disabled { opacity: .62; cursor: default; }
#context-menu hr { border: 0; border-top: 1px solid #d0d4cf; margin: 5px; }

dialog {
  min-width: 310px;
  color: #17211d;
  border: 0;
  border-radius: 10px;
  background: #faf8ee;
  box-shadow: 0 18px 55px rgba(0,0,0,.55);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog label { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
dialog input { min-height: 34px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

#toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(var(--hand) + 24px);
  transform: translateX(-50%);
  padding: 9px 14px;
  border-radius: 20px;
  color: white;
  background: rgba(10,18,14,.88);
}

@media (max-height: 680px) {
  :root { --hand: 176px; }
  .hand-card { width: 82px; height: 115px; flex-basis: 82px; }
  #hand-cards { height: 124px; }
}

@media (max-width: 700px), (pointer: coarse),
       (max-width: 950px) and (max-height: 520px) {
  :root {
    font-size: 15px;
    --strip: calc(44px + env(safe-area-inset-top));
    --hand: calc(176px + env(safe-area-inset-bottom));
    --panel: 100%;
  }

  #top-strip { padding-top: env(safe-area-inset-top); }
  .edge-tab {
    top: env(safe-area-inset-top);
    bottom: auto;
    height: 44px;
    min-width: 88px;
  }

  .overlay-panel {
    width: 100%;
    box-shadow: 0 8px 24px rgba(0,0,0,.42);
  }
  .overlay-panel > header { height: 54px; padding-inline: 14px; }
  .panel-scroll, #log-scroll { height: calc(100% - 54px); }
  .panel-scroll { padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); }
  .panel-scroll button, .panel-scroll select, .panel-scroll input,
  .overlay-panel header button { min-height: 44px; }
  .panel-scroll input, .panel-scroll select, dialog input { font-size: 16px; }

  #table-info {
    left: 9px;
    bottom: calc(var(--hand) + 8px);
    max-width: calc(100% - 18px);
    font-size: 12px;
  }

  #hand-zone > header { height: 44px; padding: 5px 10px; }
  #hand-zone > header button { min-height: 36px; }
  .hand-actions { gap: 4px; }
  .hand-scroll-button {
    display: block;
    min-width: 36px;
    padding: 0 8px;
    font-size: 24px;
    line-height: 1;
  }
  #hand-sort { padding-inline: 9px; }
  #hand-scroll {
    height: calc(100% - 44px);
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }
  #hand-cards {
    height: 124px;
    gap: 8px;
    padding: 4px 10px;
  }
  .hand-card {
    width: 82px;
    height: 115px;
    flex-basis: 82px;
  }
  .hand-insert { height: 118px; }

  #context-menu {
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: calc(8px + env(safe-area-inset-bottom));
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: min(72dvh, 590px);
    overflow-y: auto;
    border-radius: 12px;
    padding: 7px;
  }
  #context-menu button {
    min-height: 44px;
    padding: 8px 10px;
  }

  dialog {
    width: calc(100% - 28px);
    min-width: 0;
    max-width: 430px;
    margin: auto;
  }
  dialog button { min-height: 44px; }

  #toast {
    bottom: calc(var(--hand) + 14px);
    width: max-content;
    max-width: calc(100% - 24px);
    text-align: center;
  }
}

@media (max-width: 700px) and (orientation: landscape),
       (pointer: coarse) and (orientation: landscape) and (max-height: 520px),
       (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  :root { --hand: calc(132px + env(safe-area-inset-bottom)); }
  #hand-cards { height: 87px; }
  .hand-card {
    width: 58px;
    height: 82px;
    flex-basis: 58px;
    border-radius: 5px;
  }
  .hand-insert { height: 84px; }
  #table-info { display: none; }
  #view-controls {
    top: auto;
    right: 10px;
    bottom: calc(var(--hand) + 8px);
    left: auto;
    transform: none;
  }
}
