* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100svh;
  width: 100%;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #f4f1ea;
  color: #2c2a26;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

:root {
  --card-w: 78px;
  --card-h: 110px;
  --rank-size: 18px;
  --suit-size: 16px;
  --center-size: 32px;
  --gap: 6px;
}

@media (max-width: 720px) {
  :root {
    --card-w: 54px;
    --card-h: 76px;
    --rank-size: 13px;
    --suit-size: 12px;
    --center-size: 20px;
    --gap: 3px;
  }
}

@media (max-width: 400px) {
  :root {
    --card-w: 44px;
    --card-h: 62px;
    --rank-size: 11px;
    --suit-size: 10px;
    --center-size: 16px;
    --gap: 2px;
  }
}

@media (max-height: 640px) {
  :root {
    --card-w: 46px;
    --card-h: 64px;
    --rank-size: 11px;
    --suit-size: 10px;
    --center-size: 16px;
    --gap: 2px;
  }
}

#app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  height: 100vh;
  height: 100svh;
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  padding-top: max(8px, env(safe-area-inset-top));
  gap: 6px;
  overflow: hidden;
}

@media (max-width: 720px) {
  #app {
    padding: 4px 6px;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    padding-top: max(4px, env(safe-area-inset-top));
    gap: 4px;
  }
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
  color: #5b5751;
}

header h1 {
  font-size: 16px;
  margin: 0;
  letter-spacing: 1px;
  font-weight: 600;
}
@media (max-width: 720px) {
  header { font-size: 11px; gap: 4px; }
  header h1 { display: none; }
  header .meta { gap: 8px; }
}

header .meta { display: flex; gap: 12px; flex-wrap: wrap; }
header .meta b { color: #2c2a26; font-weight: 600; }

.zone {
  background: #ebe6dc;
  border-radius: 12px;
  padding: 8px;
  position: relative;
}

@media (max-width: 720px) {
  .zone { padding: 4px; border-radius: 8px; }
}

#opponent-zone {
  display: flex;
  align-items: center;
  overflow: hidden;
}
#table-zone {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}
#hand-zone {
  display: flex;
  align-items: center;
}

.deck-area {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  z-index: 2;
  pointer-events: none;
  transform: scale(0.78);
  transform-origin: bottom right;
}
@media (max-width: 720px) {
  .deck-area { transform: scale(0.65); right: 4px; bottom: 4px; }
}

.hand {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
}

@media (max-width: 720px) {
  .hand {
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    padding: 2px;
    width: 100%;
    min-width: 0;
  }
  .hand .card { flex-shrink: 0; }
  #hand-zone {
    overflow-y: auto;
    scrollbar-width: none;
  }
  #hand-zone::-webkit-scrollbar { display: none; }
}

.hand.opponent .card.face-down {
  width: calc(var(--card-w) * 0.85);
  height: calc(var(--card-h) * 0.85);
}

.deck {
  position: relative;
  width: calc(var(--card-w) * 1.45);
  height: var(--card-h);
}
.deck .trump-card {
  position: absolute;
  left: 0;
  top: 0;
}
.deck .face-down {
  position: absolute;
  right: 0;
  top: 0;
  box-shadow: -2px 0 6px rgba(0,0,0,0.10);
}

.table {
  flex: 1;
  display: flex;
  gap: var(--gap);
  min-height: var(--card-h);
  min-width: 0;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border: 2px dashed #d1c9b8;
  border-radius: 10px;
  transition: background 0.15s;
  flex-wrap: wrap;
  overflow: hidden;
}

@media (max-width: 720px) {
  .table {
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    overflow: hidden;
  }
  .table .slot { flex-shrink: 0; }
}
.table.drop-active { background: #f6efde; }

.slot {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
}
.slot .card {
  position: absolute;
  left: 0;
  top: 0;
}
.slot .defense {
  left: calc(var(--card-w) * 0.22);
  top: calc(var(--card-h) * 0.16);
}

.discard {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  border: 2px dashed #d1c9b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #8a857c;
  flex-shrink: 0;
}
.discard.has-cards {
  border-style: solid;
  background: #ddd5c5;
  color: #2c2a26;
}

/* Card */
.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 7px;
  background: #ffffff;
  border: 1px solid #c8c0ad;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 5px;
  font-weight: 600;
  cursor: default;
  transition: transform 0.12s, box-shadow 0.12s;
  position: relative;
}
.card.red { color: #c8312b; }
.card.black { color: #1f1d1a; }
.card .corner { display: flex; flex-direction: column; align-items: flex-start; line-height: 1; }
.card .corner.bottom { align-self: flex-end; transform: rotate(180deg); }
.card .corner .rank { font-size: var(--rank-size); }
.card .corner .suit { font-size: var(--suit-size); }
.card .center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--center-size);
  opacity: 0.85;
}

.card.trump { box-shadow: 0 0 0 2px #c89b3a, 0 2px 4px rgba(0,0,0,0.08); }

.card.face-down {
  background:
    repeating-linear-gradient(45deg, #b5b0a2 0 6px, #a39e90 6px 12px);
  border-color: #8a857c;
}
.card.face-down .corner, .card.face-down .center { display: none; }

.card.in-hand { cursor: pointer; }
.card.in-hand.legal { box-shadow: 0 0 0 2px #6aa84f, 0 2px 4px rgba(0,0,0,0.08); }
.card.in-hand.transferable { box-shadow: 0 0 0 2px #4a7fbf, 0 2px 4px rgba(0,0,0,0.08); }
.card.in-hand.illegal { opacity: 0.55; }

@media (hover: hover) {
  .card.in-hand.legal:hover, .card.in-hand.transferable:hover {
    transform: translateY(-8px);
  }
}
.card.in-hand.legal:active, .card.in-hand.transferable:active {
  transform: translateY(-4px) scale(0.98);
}
.card.dragging { opacity: 0.4; }
.card.touch-drag {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  opacity: 0.85;
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

#controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 4px;
  flex-wrap: wrap;
}
button {
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid #c8c0ad;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
  color: #2c2a26;
  transition: background 0.1s;
  min-height: 40px;
  min-width: 70px;
}
@media (max-width: 720px) {
  button { padding: 6px 12px; min-height: 32px; min-width: 60px; font-size: 13px; }
}
@media (hover: hover) {
  button:hover:not(:disabled) { background: #f0eada; }
}
button:active:not(:disabled) { background: #e2d9c4; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: #6aa84f; color: #fff; border-color: #5a943f; }
button.primary:active:not(:disabled) { background: #4d8235; }
button.danger { background: #c8312b; color: #fff; border-color: #a82822; }
button.danger:active:not(:disabled) { background: #8b211c; }

#status {
  text-align: center;
  font-size: 13px;
  color: #5b5751;
  min-height: 18px;
  padding: 0 6px;
}
@media (max-width: 720px) {
  #status { font-size: 11px; min-height: 14px; }
}
#status.alert { color: #c8312b; font-weight: 600; }

#banner {
  position: fixed;
  inset: 0;
  background: rgba(244,241,234,0.92);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 10;
}
#banner.show { display: flex; }
#banner h2 { font-size: 28px; margin: 0; text-align: center; padding: 0 20px; }

.slot.drop-target {
  outline: 3px solid #6aa84f;
  outline-offset: 2px;
  border-radius: 8px;
}

#choice-modal {
  position: fixed;
  inset: 0;
  background: rgba(44, 42, 38, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}
#choice-modal.show { display: flex; }
.choice-box {
  background: #f4f1ea;
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 320px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
#choice-card .card {
  pointer-events: none;
}
.choice-box p {
  margin: 0;
  text-align: center;
  font-size: 14px;
  color: #2c2a26;
}
.choice-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
