:root {
  color-scheme: light;
  --bg: #0f172a;
  --panel: #111827;
  --text: #f8fafc;
  --accent: #22c55e;
  --accent-2: #38bdf8;
  --danger: #ef4444;
  --grid: #1e293b;
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.4);
  --glow: 0 0 20px rgba(56, 189, 248, 0.3);
}

* {
  box-sizing: border-box;
  font-family: "Trebuchet MS", system-ui, sans-serif;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #0f172a, #020617);
  color: var(--text);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.app {
  width: min(860px, 100%);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(135deg, rgba(17, 24, 39, 0.95), rgba(15, 23, 42, 0.95));
  padding: 18px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
}

header p {
  margin: 0;
  font-size: 0.9rem;
  color: #cbd5f5;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 6px;
}

input[type="text"],
input[type="file"],
button {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #334155;
  padding: 10px 12px;
  background: #0b1220;
  color: var(--text);
  font-size: 0.95rem;
}

input[type="file"] {
  padding: 8px 12px;
}

button {
  cursor: pointer;
  background: var(--accent);
  color: #052e16;
  font-weight: 700;
  letter-spacing: 0.4px;
  box-shadow: var(--glow);
  border: none;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.game-panel {
  position: relative;
  background: var(--panel);
  border-radius: 22px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

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

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-wrap {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  border: 2px solid var(--accent-2);
  background: #0b1220;
  flex-shrink: 0;
}

.avatar-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.65);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.avatar-wrap.happy .avatar-overlay,
.avatar-wrap.dead .avatar-overlay {
  opacity: 1;
}

.avatar-wrap.dead {
  border-color: var(--danger);
}

.hud-stats {
  display: flex;
  flex-direction: column;
  text-align: right;
  font-size: 0.85rem;
}

canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  background: var(--grid);
  touch-action: none;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  justify-items: center;
  margin-top: 8px;
}

.dpad button {
  background: #1f2937;
  color: var(--text);
  border: 1px solid #334155;
  width: 100%;
  min-height: 48px;
  box-shadow: none;
}

.dpad .empty {
  opacity: 0;
}

.message {
  text-align: center;
  font-size: 0.95rem;
  color: #cbd5f5;
}

.footer {
  text-align: center;
  font-size: 0.8rem;
  color: #94a3b8;
}

@media (max-width: 540px) {
  header h1 {
    font-size: 1.2rem;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .hud {
    flex-direction: column;
    align-items: flex-start;
  }

  .hud-stats {
    text-align: left;
  }
}
