﻿:root {
  --bg-dark: #0d2124;
  --bg-panel: #153236;
  --bg-cream: #f6f1e7;
  --bg-cream-dark: #e5dccb;
  --accent-gold: #f5a623;
  --accent-gold-light: #ffd166;
  --accent-green: #2ecc71;
  --accent-red: #e74c3c;
  --accent-blue: #3498db;
  --text-dark: #12282b;
  --text-light: #f9f6f0;
  --border-pixel: #24170e;
  --wood-dark: #4f2f17;
  --wood-mid: #7d4e28;
  --wood-light: #b87b48;
  --container-max: 1220px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Kanit', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(rgba(245, 166, 35, 0.09) 2px, transparent 2px),
    radial-gradient(rgba(255, 255, 255, 0.04) 2px, var(--bg-dark) 2px);
  background-size: 32px 32px;
  background-position: 0 0, 16px 16px;
  color: var(--text-light);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.55;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* Crisp Pixel Art Boxes */
.pixel-box {
  background: var(--bg-cream);
  color: var(--text-dark);
  border: 4px solid var(--border-pixel);
  box-shadow:
    inset -4px -4px 0px 0px #cfc0a6,
    inset 4px 4px 0px 0px #ffffff,
    6px 6px 0px 0px rgba(0, 0, 0, 0.45);
  border-radius: 6px;
  position: relative;
}

.pixel-box-dark {
  background: linear-gradient(180deg, #183a3f 0%, #122b2f 100%);
  color: var(--text-light);
  border: 4px solid #071315;
  box-shadow:
    inset -4px -4px 0px 0px #0c1d20,
    inset 4px 4px 0px 0px #27565d,
    6px 6px 0px 0px rgba(0, 0, 0, 0.5);
  border-radius: 6px;
}

/* Tactile Pixel Buttons - Touch Friendly (min 48px height) */
.pixel-btn {
  font-family: 'Kanit', sans-serif;
  font-weight: 600;
  font-size: clamp(0.95rem, 1.5vw, 1.08rem);
  min-height: 48px;
  padding: 10px 20px;
  cursor: pointer;
  border: 3px solid var(--border-pixel);
  background: var(--accent-gold);
  color: #1a1208;
  border-radius: 4px;
  box-shadow:
    inset -3px -3px 0px 0px #c67d0a,
    inset 3px 3px 0px 0px #ffe396,
    4px 4px 0px 0px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  user-select: none;
  touch-action: manipulation;
}

.pixel-btn:hover {
  filter: brightness(1.06);
  transform: translate(-1px, -1px);
}

.pixel-btn:active {
  transform: translate(2px, 2px);
  box-shadow:
    inset -2px -2px 0px 0px #c67d0a,
    inset 2px 2px 0px 0px #ffe396,
    1px 1px 0px 0px rgba(0, 0, 0, 0.4);
}

.pixel-btn.btn-green {
  background: #2ecc71;
  color: #072514;
  box-shadow:
    inset -3px -3px 0px 0px #1f9952,
    inset 3px 3px 0px 0px #86f7b5,
    4px 4px 0px 0px rgba(0, 0, 0, 0.4);
}

.pixel-btn.btn-blue {
  background: #3898ec;
  color: #ffffff;
  box-shadow:
    inset -3px -3px 0px 0px #1c65a6,
    inset 3px 3px 0px 0px #7bc2ff,
    4px 4px 0px 0px rgba(0, 0, 0, 0.4);
}

.pixel-btn.btn-secondary {
  background: #e3dacb;
  color: var(--text-dark);
  box-shadow:
    inset -3px -3px 0px 0px #b4a792,
    inset 3px 3px 0px 0px #ffffff,
    4px 4px 0px 0px rgba(0, 0, 0, 0.4);
}

/* Sticky Top Header */
.top-header {
  background: rgba(10, 26, 28, 0.96);
  backdrop-filter: blur(6px);
  border-bottom: 4px solid var(--accent-gold);
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.header-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.pixel-badge {
  background: var(--accent-gold);
  color: #161005;
  font-weight: 700;
  padding: 4px 10px;
  border: 2px solid #000;
  font-size: 0.82rem;
  box-shadow: 2px 2px 0 #000;
  letter-spacing: 0.4px;
  display: inline-block;
  white-space: nowrap;
}

.player-hud {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hud-pill {
  background: #16363a;
  border: 2px solid #356c74;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.92rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hud-pill strong {
  color: var(--accent-gold-light);
}

/* Main App Container */
.app-container {
  max-width: var(--container-max);
  margin: 18px auto;
  padding: 0 16px 48px;
}

/* Responsive Step Progress Bar */
.phase-stepper {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.step-item {
  background: #122b2f;
  border: 3px solid #265158;
  padding: 10px 8px;
  text-align: center;
  font-size: 0.88rem;
  color: #9ec0c5;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-item.active {
  background: var(--accent-gold);
  color: #1a1102;
  border-color: #ffffff;
  font-weight: 700;
  transform: translateY(-2px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
}

.step-item.completed {
  background: #194d3d;
  border-color: #2ecc71;
  color: #dcfff2;
}

/* Hero Banner Layout */
.hero-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 22px;
  align-items: center;
}

/* Pixel Canvas Stage */
.pixel-scene-stage {
  width: 100%;
  border: 4px solid #24160c;
  background: #132c30;
  box-shadow:
    inset 0 0 0 2px #f5a623,
    6px 6px 0 rgba(0, 0, 0, 0.55);
  position: relative;
  overflow: hidden;
  border-radius: 6px;
}

.pixel-canvas-responsive {
  width: 100%;
  height: auto;
  aspect-ratio: 560 / 260;
  display: block;
  image-rendering: auto;
}

/* Live Negotiation Arena */
.negotiation-arena {
  position: relative;
  background: #132d31;
  border: 4px solid #000;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.5);
  margin-bottom: 18px;
}

.arena-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(11, 26, 29, 0.96);
  border-bottom: 3px solid var(--accent-gold);
  flex-wrap: wrap;
  gap: 10px;
}

.meter-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.pixel-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
}

.meter-bar-wrap {
  width: 120px;
  height: 18px;
  background: #081315;
  border: 2px solid #fff;
  padding: 2px;
  border-radius: 2px;
}

.meter-bar-fill {
  height: 100%;
  background: var(--accent-green);
  transition: width 0.35s ease, background-color 0.35s ease;
}

.arena-footer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: rgba(11, 24, 26, 0.96);
  border-top: 3px solid #2c1e14;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.92rem;
}

/* RPG Dialogue Box */
.rpg-dialogue-box {
  background: #fffdf8;
  color: #132a2e;
  border: 4px solid #1b1209;
  border-radius: 6px;
  box-shadow:
    inset -4px -4px 0px 0px #dfd3be,
    inset 4px 4px 0px 0px #ffffff,
    6px 6px 0px 0px rgba(0, 0, 0, 0.5);
  padding: clamp(14px, 2.5vw, 22px);
  margin-bottom: 18px;
  position: relative;
}

.speaker-ribbon {
  display: inline-block;
  background: var(--accent-gold);
  color: #1b1209;
  font-weight: 700;
  padding: 4px 14px;
  border: 3px solid #1b1209;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.25);
  font-size: clamp(0.92rem, 1.5vw, 1.02rem);
}

.dialogue-text {
  font-size: clamp(1.05rem, 2vw, 1.24rem);
  font-weight: 600;
  line-height: 1.6;
  margin: 12px 0 14px;
  color: #102327;
}

.coach-hint-bar {
  background: #e6f4f1;
  border-left: 5px solid #16a085;
  padding: 10px 14px;
  font-size: clamp(0.88rem, 1.4vw, 0.96rem);
  color: #0c453a;
  border-radius: 0 4px 4px 0;
}

/* Choice Options Grid */
.choices-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.choice-card {
  background: #faf6ee;
  color: #132a2e;
  border: 3px solid #2c1e14;
  border-radius: 6px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  font-family: 'Kanit', sans-serif;
  font-size: clamp(0.98rem, 1.6vw, 1.08rem);
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.1s, background-color 0.15s, border-color 0.15s;
  touch-action: manipulation;
}

.choice-card:hover,
.choice-card:focus-visible {
  background: #fff9e6;
  border-color: var(--accent-gold);
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.45);
}

.choice-card:active {
  transform: translate(1px, 1px);
}

.choice-key {
  background: var(--bg-dark);
  color: var(--accent-gold-light);
  font-weight: 700;
  min-width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #000;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 2px;
}

/* Product & Buyer Selection Cards Grid */
.cards-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.selectable-card {
  background: #fbf8f1;
  color: var(--text-dark);
  border: 4px solid #2c1e14;
  border-radius: 6px;
  padding: 16px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  touch-action: manipulation;
  position: relative;
}

.selectable-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-gold);
}

.selectable-card.selected {
  border-color: #1f9952;
  background: #eefdf4;
  box-shadow: 0 0 0 3px #2ecc71, 6px 6px 0 rgba(0, 0, 0, 0.5);
}

.selected-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #2ecc71;
  color: #062312;
  font-weight: 800;
  font-size: 0.76rem;
  padding: 2px 8px;
  border: 2px solid #000;
  border-radius: 4px;
}

/* Pitch Sheet One-Page Builder */
.pitch-sheet-layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 20px;
  align-items: start;
}

.pitch-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.pitch-paper-preview {
  background: #fffef9;
  color: #182b2e;
  border: 4px solid #1f3a3d;
  border-radius: 6px;
  padding: clamp(16px, 2.5vw, 22px);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.45);
  position: relative;
}

/* Form Controls - Mobile Friendly (16px+ prevents iOS auto-zoom) */
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.98rem;
}

.pixel-input,
.pixel-select {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  font-family: 'Kanit', sans-serif;
  font-size: 1rem; /* >=16px prevents iOS Safari zoom on focus */
  border: 3px solid #2c1e14;
  border-radius: 4px;
  background: #ffffff;
  color: #132a2e;
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, 0.12);
}

.pixel-input:focus,
.pixel-select:focus {
  outline: 3px solid var(--accent-gold);
}

/* Score & Rank Badges */
.rank-badge-large {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.35rem, 3.5vw, 2.1rem);
  font-weight: 800;
  padding: 10px 22px;
  background: var(--accent-gold);
  color: #1b1102;
  border: 4px solid #000;
  border-radius: 6px;
  box-shadow: 6px 6px 0 #000;
  margin: 12px 0;
  text-align: center;
}

/* Responsive Leaderboard Table + Mobile Card View */
.table-responsive-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.pixel-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.96rem;
}

.pixel-table th {
  background: #132a2e;
  color: var(--accent-gold-light);
  padding: 11px 12px;
  text-align: left;
  border: 2px solid #2c1e14;
  white-space: nowrap;
}

.pixel-table td {
  padding: 10px 12px;
  border: 2px solid #cbbba0;
  background: #fffcf5;
  color: #132a2e;
}

.pixel-table tr.highlight-row td {
  background: #fff3cd;
  font-weight: 700;
}

/* Audio & TTS Buttons */
.tts-btn {
  background: #173a3f;
  color: #fff;
  border: 2px solid #000;
  border-radius: 4px;
  min-height: 40px;
  padding: 6px 12px;
  font-family: 'Kanit', sans-serif;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  touch-action: manipulation;
}

.tts-btn:hover {
  background: #23535a;
}

/* =========================================================
   RESPONSIVE BREAKPOINTS (Tablet, Landscape & Mobile)
   ========================================================= */

/* Tablet Landscape & Medium Screens (<= 1100px) */
@media (max-width: 1100px) {
  .cards-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .hero-grid {
    grid-template-columns: 1fr;
  }
}

/* Tablet Portrait (<= 860px) */
@media (max-width: 860px) {
  .pitch-sheet-layout {
    grid-template-columns: 1fr;
  }
  .form-grid-3 {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .phase-stepper {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 6px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .step-item {
    flex: 0 0 auto;
    min-width: 165px;
    scroll-snap-align: start;
  }
}

/* Mobile Smartphones (<= 640px) */
@media (max-width: 640px) {
  .top-header {
    padding: 8px 12px;
  }
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .brand-title {
    justify-content: space-between;
  }
  .player-hud {
    justify-content: space-between;
    width: 100%;
    gap: 6px;
  }
  .hud-pill {
    font-size: 0.82rem;
    padding: 4px 8px;
    flex: 1 1 auto;
    justify-content: center;
  }
  .app-container {
    margin: 12px auto;
    padding: 0 10px 36px;
  }
  .pixel-box,
  .pixel-box-dark {
    padding: 14px !important;
    box-shadow:
      inset -3px -3px 0px 0px rgba(0, 0, 0, 0.15),
      inset 3px 3px 0px 0px rgba(255, 255, 255, 0.4),
      4px 4px 0px 0px rgba(0, 0, 0, 0.45);
  }
  .cards-grid-4 {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .pitch-fields-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .arena-top-bar,
  .arena-footer-bar {
    padding: 10px 12px;
    flex-direction: column;
    align-items: flex-start;
  }
  .meter-group {
    width: 100%;
    justify-content: space-between;
  }
  .pixel-btn {
    width: 100%;
    padding: 12px 16px;
  }
  .choice-card {
    padding: 12px;
    gap: 10px;
  }
  /* Convert Leaderboard Table into Stacked Mobile Cards on small screens */
  .pixel-table thead {
    display: none;
  }
  .pixel-table,
  .pixel-table tbody,
  .pixel-table tr,
  .pixel-table td {
    display: block;
    width: 100%;
  }
  .pixel-table tr {
    margin-bottom: 12px;
    border: 3px solid #2c1e14;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.25);
  }
  .pixel-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
    padding: 8px 12px;
    border: none;
    border-bottom: 1px solid #dfd5c3;
    gap: 10px;
  }
  .pixel-table td:last-child {
    border-bottom: none;
  }
  .pixel-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #132a2e;
    text-align: left;
    flex-shrink: 0;
  }
}

/* Print Style for Pitch Sheet & Certificate */
@media print {
  .top-header,
  .phase-stepper,
  .pixel-btn,
  .tts-btn {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
  }
  .pixel-box {
    box-shadow: none;
    border: 2px solid #000;
  }
}
