/* Terminal Duel — browser edition */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0c1017;
  --felt: radial-gradient(ellipse at 50% 30%, #182337 0%, #0c1017 75%);
  --panel: #161d2b;
  --line: #2a3550;
  --gold: #c9a959;
  --red: #ff6b6b;
  --blue: #6bb8ff;
  --green: #7bd88a;
  --text: #d8dee9;
  --dim: #7a869e;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

#game {
  display: flex;
  min-height: 100vh;
}

/* ---------------------------------------------------------------- board */

#board {
  flex: 1;
  background: var(--felt);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 18px 24px;
}

.bar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 4px 10px;
  font-size: 15px;
  color: var(--dim);
}

.bar .pname { font-weight: 700; color: var(--text); font-size: 17px; }
.bar .pname.opp { color: var(--red); }
.bar .lp { color: var(--green); font-weight: 700; }

#mid-bar {
  justify-content: center;
  gap: 14px;
  font-size: 14px;
}

.phase-chip {
  background: var(--panel);
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 12px;
  padding: 2px 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* sim-verified badge + report panel */
.sim-chip {
  margin-left: auto;
  cursor: pointer;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 11px;
  padding: 2px 10px;
  transition: box-shadow .15s;
}
.sim-chip:hover { box-shadow: 0 0 10px rgba(74, 222, 128, .5); }

.sim-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  font-size: 13px;
}
.sim-row b { width: 48px; }
.sim-row i { color: var(--dim); font-size: 11px; font-style: normal; }
.sim-bar {
  flex: 1;
  height: 8px;
  background: #1a2233;
  border-radius: 4px;
  overflow: hidden;
}
.sim-bar div { height: 100%; background: var(--green); border-radius: 4px; }
.sim-foot { font-size: 10px; opacity: .6; }
.p-dim { color: var(--dim); font-size: 13px; }

.field-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  min-height: 162px;
}

.slot {
  width: 118px;
  height: 158px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  display: flex;
}

/* ---------------------------------------------------------------- cards */

.card {
  width: 148px;
  min-height: 196px;
  background: linear-gradient(160deg, #232c3f, #171e2c);
  border: 1px solid hsl(var(--hue, 210), 40%, 45%);
  border-radius: 8px;
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  transition: transform .12s, box-shadow .12s;
}

.c-name {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.c-art {
  height: 78px;
  border-radius: 5px;
  background:
    radial-gradient(circle at 30% 30%, hsl(var(--hue, 210), 60%, 38%), hsl(var(--hue, 210), 55%, 18%));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  overflow: hidden;
}

.c-img, .m-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 3px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .55));
}

.c-stars {
  position: relative;
  z-index: 1;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 1px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .9);
  align-self: flex-end;
  margin-top: auto;
}

.c-glyph {
  font-size: 30px;
  font-weight: 900;
  color: rgba(255, 255, 255, .85);
  text-shadow: 0 2px 6px rgba(0, 0, 0, .6);
}

/* spells & traps in hand (kind hue is set inline by cardEl) */
.c-kind {
  align-self: center;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1.5px;
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid hsl(var(--hue, 210), 70%, 60%);
  color: hsl(var(--hue, 210), 80%, 75%);
}

/* trap row — face-down cards behind each player's monsters */
.trap-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  min-height: 40px;
  align-items: center;
}

.trap-card {
  width: 32px;
  height: 44px;
  border-radius: 4px;
  background:
    radial-gradient(circle at 30% 30%, #4a2a5e, #1d1226);
  border: 1px solid #6b3f8a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: rgba(255, 255, 255, .25);
  position: relative;
}

.trap-card::after { content: "?"; }
.trap-card.mine { border-color: hsl(325, 70%, 55%); color: hsl(325, 80%, 70%); }
.trap-card.mine::after { content: "✦"; }
.trap-card.enter { animation: summonIn .4s ease-out; }

/* center-screen card flash for spell/trap activation */
.card.flash {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 65;
  pointer-events: none;
  animation: cardFlash .85s ease-out forwards;
  box-shadow: 0 0 34px hsl(var(--hue, 210), 80%, 60%);
}

@keyframes cardFlash {
  0% { transform: translate(-50%, -50%) scale(.35); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  65% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -65%) scale(.85); opacity: 0; }
}

.c-stats {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
}

.c-stats .atk, .m-stats .atk { color: var(--red); }
.c-stats .def, .m-stats .def { color: var(--blue); }

.c-text {
  color: var(--dim);
  font-size: 10.5px;
  line-height: 1.25;
  flex: 1;
}

.c-trib {
  color: var(--gold);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ---------------------------------------------------------------- monsters on field */

.monster {
  width: 118px;
  height: 158px;
  background: linear-gradient(160deg, #232c3f, #171e2c);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  transition: transform .12s, box-shadow .12s;
}

.monster.attack { border-color: #b0632f; }
.monster.defense { border-color: #3f6f9e; }

.m-name {
  font-weight: 700;
  font-size: 11px;
  text-align: center;
  height: 28px;
  overflow: hidden;
}

.m-art {
  width: 100%;
  height: 62px;
  border-radius: 4px;
  background:
    radial-gradient(circle at 30% 30%, hsl(var(--hue, 210), 60%, 38%), hsl(var(--hue, 210), 55%, 18%));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.m-art .c-glyph { font-size: 22px; }

.m-stats { font-weight: 700; font-size: 13px; }

/* the stat matching the battle position stands out */
.m-stats .active {
  font-size: 17px;
  text-shadow: 0 0 8px currentColor;
}
.m-stats .dim {
  font-size: 10.5px;
  font-weight: 400;
  opacity: .5;
}

/* equipped spell icons under a monster's stats */
.equips {
  display: flex;
  gap: 3px;
  justify-content: center;
  margin-top: 2px;
  min-height: 20px;
}

.eq {
  width: 20px;
  height: 20px;
  object-fit: contain;
  image-rendering: pixelated;
  background: #1d1226;
  border: 1px solid hsl(175, 60%, 45%);
  border-radius: 3px;
  box-shadow: 0 0 6px rgba(64, 200, 180, .4);
}

.eq-chip {
  font-size: 8px;
  font-weight: 900;
  color: hsl(175, 70%, 65%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.m-stats .atk.buff { color: var(--green); }

.m-pos {
  font-size: 9.5px;
  letter-spacing: 1px;
  color: var(--dim);
}

/* ---------------------------------------------------------------- interactivity */

.selectable { cursor: pointer; }
.selectable:hover { transform: translateY(-6px); box-shadow: 0 6px 18px rgba(0, 0, 0, .5); }

.selected {
  border-color: var(--gold) !important;
  box-shadow: 0 0 14px rgba(201, 169, 89, .55);
  transform: translateY(-6px);
}

.picked {
  border-color: var(--green) !important;
  box-shadow: 0 0 12px rgba(123, 216, 138, .5);
}

.targetable {
  cursor: crosshair;
  border-color: var(--red) !important;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(255, 107, 107, .4); }
  50% { box-shadow: 0 0 18px rgba(255, 107, 107, .9); }
}

/* ---------------------------------------------------------------- hand */

#hand {
  display: flex;
  justify-content: center;
  gap: 12px;
  min-height: 208px;
  padding-top: 4px;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------- sidebar */

#side {
  width: 340px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
}

#side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#turn-ind {
  display: flex;
  gap: 16px;
  align-items: center;
}

.ind {
  display: flex;
  align-items: center;
  gap: 7px;
}

.ind .dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #141b2a;
  color: var(--dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  transition: all .3s;
}

.ind.active .dot {
  border-color: var(--gold);
  background: radial-gradient(circle at 35% 30%, #6b5a2a, #3a2f14);
  color: var(--gold);
  animation: indPulse 1.6s ease-in-out infinite;
}

@keyframes indPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(201, 169, 89, .4); }
  50% { box-shadow: 0 0 20px rgba(201, 169, 89, .85); }
}

.ind-name {
  font-size: 12px;
  color: var(--dim);
  max-width: 70px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ind.active .ind-name { color: var(--gold); }

#notice {
  min-height: 22px;
  font-size: 13px;
  color: var(--red);
  opacity: 0;
  transition: opacity .2s;
}
#notice.show { opacity: 1; }

#turn-controls { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  background: #232c3f;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

.btn:hover:not(:disabled) { background: #2d3a55; border-color: var(--gold); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { border-color: var(--gold); color: var(--gold); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.end { border-color: var(--blue); color: var(--blue); }
.btn.concede { font-size: 11px; padding: 4px 10px; color: var(--dim); }
.btn.big { font-size: 16px; padding: 12px 28px; }

#log {
  flex: 1;
  overflow-y: auto;
  background: #0e1420;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--dim);
  min-height: 120px;
}

#log div { margin-bottom: 2px; }

/* ---------------------------------------------------------------- overlay */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 13, .92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#overlay.show { display: flex; }

.panel {
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 36px 44px;
  text-align: center;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
}

.panel h1 { color: var(--gold); letter-spacing: 4px; margin-bottom: 8px; }
.panel h2 { color: var(--gold); margin-bottom: 10px; }
.panel p { color: var(--dim); margin: 10px 0 18px; }
.panel .sub { margin-top: 0; }
.panel .win { font-size: 34px; }

.title { font-size: 52px; }

.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  text-align: left;
}

.form label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--dim);
}

.form input, .form select {
  background: #0e1420;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  width: 220px;
}

.hidden { display: none; }

.pick-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 10px;
}

/* ---------------------------------------------------------------- popup prompts */

#popup, #cardtip {
  position: fixed;
  z-index: 70;
  display: none;
  flex-direction: column;
  gap: 7px;
  min-width: 190px;
  max-width: 250px;
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 9px;
  padding: 10px 12px 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .65);
  font-size: 13px;
}

#cardtip { pointer-events: none; }

#popup.show { display: flex; animation: popIn .16s ease-out; }
#cardtip.show { display: flex; animation: tipIn .25s ease-out; }
@keyframes tipIn { from { opacity: 0; } }
@keyframes popIn {
  from { transform: scale(.82); opacity: 0; }
}

#popup .arrow, #cardtip .arrow {
  position: absolute;
  bottom: -6px;
  left: 50%;
  width: 11px;
  height: 11px;
  transform: translateX(-50%) rotate(45deg);
  background: var(--panel);
  border-right: 1px solid var(--gold);
  border-bottom: 1px solid var(--gold);
}

#popup.below .arrow, #cardtip.below .arrow {
  bottom: auto;
  top: -6px;
  border: none;
  border-left: 1px solid var(--gold);
  border-top: 1px solid var(--gold);
}

.p-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.p-title { font-weight: 700; font-size: 14px; }

.p-close {
  background: none;
  border: none;
  color: var(--dim);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
}
.p-close:hover { color: var(--red); }

.p-text { color: var(--dim); font-size: 12.5px; line-height: 1.45; }
.p-eff { color: var(--text); }
.p-reason { color: var(--red); }

.p-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.p-btns .btn { padding: 6px 11px; font-size: 12px; }

/* ---------------------------------------------------------------- fx layer */

#fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

#toast {
  position: fixed;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 3px 14px rgba(0, 0, 0, .85);
  opacity: 0;
  pointer-events: none;
  z-index: 55;
}

#toast.show { animation: toastAnim 1.4s ease-out; }

@keyframes toastAnim {
  0% { opacity: 0; transform: translateX(-50%) scale(.7); }
  15% { opacity: 1; transform: translateX(-50%) scale(1.05); }
  25% { transform: translateX(-50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

/* summon drop-in */
.monster.enter { animation: summonIn .45s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes summonIn {
  from { transform: translateY(-38px) scale(.4); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

/* position switch flip */
.monster.switchanim { animation: posFlip .4s ease-in-out; }
@keyframes posFlip {
  50% { transform: rotateY(90deg) scale(1.08); }
}

/* effect trigger glow */
.monster.fx-glow { animation: fxGlow .6s ease-out; }
@keyframes fxGlow {
  40% { box-shadow: 0 0 20px var(--gold), 0 0 34px rgba(201, 169, 89, .5); }
}

/* destruction ghost */
.monster.ghost {
  pointer-events: none;
  animation: die .6s ease-in forwards;
  z-index: 60;
}
@keyframes die {
  20% { transform: rotate(-4deg) scale(1.04); filter: brightness(1.4); }
  100% {
    transform: translateY(46px) rotate(7deg) scale(.75);
    opacity: 0;
    filter: grayscale(1) brightness(.45);
  }
}

/* slash across an attacked target */
.slash {
  position: fixed;
  width: 90px;
  height: 7px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 0 14px #fff, 0 0 28px var(--red);
  animation: slashAnim .28s ease-out forwards;
  z-index: 61;
}
@keyframes slashAnim {
  from { transform: rotate(-35deg) scaleX(.2); opacity: 1; }
  to { transform: rotate(-35deg) scaleX(1.5); opacity: 0; }
}

/* floating damage / heal numbers */
.flytext {
  position: fixed;
  transform: translateX(-50%);
  font-weight: 900;
  font-size: 24px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .8);
  animation: flyUp 1s ease-out forwards;
  z-index: 62;
}
.flytext.dmg { color: var(--red); }
.flytext.heal { color: var(--green); }
@keyframes flyUp {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(-52px); }
}

/* LP number flash */
.bar .lp { display: inline-block; }
.lp-down { animation: lpHit .55s ease-out; }
.lp-up { animation: lpGain .55s ease-out; }
@keyframes lpHit {
  30% { color: var(--red); transform: scale(1.4); }
}
@keyframes lpGain {
  30% { color: var(--green); transform: scale(1.4); }
}

/* board shake on destruction */
#board.shake { animation: shakeAnim .32s ease-in-out; }
@keyframes shakeAnim {
  20% { transform: translate(-5px, 2px); }
  45% { transform: translate(5px, -2px); }
  70% { transform: translate(-3px, 1px); }
  100% { transform: translate(0, 0); }
}

/* new cards slide into the hand */
.card.draw-in { animation: drawIn .38s ease-out backwards; }
.card.draw-in:nth-child(n+2) { animation-delay: .04s; }
@keyframes drawIn {
  from { transform: translate(70px, 46px) rotate(8deg); opacity: 0; }
  to { transform: translate(0, 0) rotate(0); opacity: 1; }
}
