/* ===========================================================
   Pocket Portfolio — HeartGold / SoulSilver inspired styling
   =========================================================== */

:root {
  --ink: #2b2b33;
  --ink-soft: #5a5a66;
  --paper: #fbfbf3;
  --paper-2: #eef0e6;
  --ui-blue: #4a82c8;
  --ui-blue-2: #2c5aa0;
  --ui-blue-3: #16264a;
  --ui-blue-line: #9cc0ef;
  --gold: #e8c45a;
  --gold-2: #b8893a;
  --silver: #c7cfdb;
  --navy: #0c1a2e;
  --navy-2: #112b4c;
  --red: #e0584c;
  --green: #5fae4f;
  --shadow: rgba(8, 16, 32, 0.45);
  --font-pixel: "Press Start 2P", monospace;
  --font-text: "VT323", "Courier New", monospace;
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--navy);
  font-family: var(--font-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* Desktop backdrop behind the handheld */
body {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(120% 90% at 50% -10%, #1b3c66 0%, #0c1a2e 55%, #060d18 100%);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 26px 26px;
  pointer-events: none;
}

/* ============================ Device ============================ */
#device {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  background: var(--navy);
  z-index: 1;
}

#device-top-bar {
  display: none; /* visible only on desktop bezel */
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 8px;
  color: var(--silver);
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 2px;
}
.device-light {
  width: 9px; height: 9px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #9affb0, #2c8c3c);
  box-shadow: 0 0 6px #4cff7a;
}
.device-light.alt { background: radial-gradient(circle at 30% 30%, #ff9a9a, #b83030); box-shadow: 0 0 6px #ff6a6a; }

/* ===== Top screen: the game ===== */
#screen-top {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #0a1c10;
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ===== Bottom screen: touch controls ===== */
#screen-bottom {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: linear-gradient(180deg, #14233a, #0a1426);
  border-top: 3px solid #06101f;
  user-select: none;
}

/* D-pad */
#dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 132px; height: 132px;
}
.pad {
  border: none;
  background: linear-gradient(180deg, #3a4761, #222c40);
  color: #cdd6e6;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.12), 0 2px 3px rgba(0,0,0,0.4);
}
.pad:active { background: #5274b0; color: #fff; transform: translateY(1px); }
.pad.up { grid-area: 1 / 2; border-radius: 8px 8px 0 0; }
.pad.left { grid-area: 2 / 1; border-radius: 8px 0 0 8px; }
.pad.center { grid-area: 2 / 2; background: #2a3550; box-shadow: inset 0 0 6px rgba(0,0,0,0.5); cursor: default; }
.pad.right { grid-area: 2 / 3; border-radius: 0 8px 8px 0; }
.pad.down { grid-area: 3 / 2; border-radius: 0 0 8px 8px; }

/* center system buttons */
#bottom-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.sys-btn {
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 1px;
  color: #0c1a2e;
  background: linear-gradient(180deg, #f3e7bf, #d8c489);
  border: 2px solid #8a6f33;
  border-radius: 20px;
  padding: 8px 14px;
  min-width: 92px;
  cursor: pointer;
  box-shadow: 0 2px 0 #6f5526;
}
.sys-btn:active { transform: translateY(2px); box-shadow: none; }

/* A / B buttons */
#ab {
  position: relative;
  width: 132px; height: 132px;
}
.action {
  position: absolute;
  width: 58px; height: 58px;
  border-radius: 50%;
  border: 3px solid rgba(0,0,0,0.35);
  font-family: var(--font-pixel);
  font-size: 16px;
  color: #fff;
  cursor: pointer;
  box-shadow: inset 0 3px 0 rgba(255,255,255,0.25), 0 3px 4px rgba(0,0,0,0.45);
}
.action:active { transform: translateY(2px); box-shadow: inset 0 0 8px rgba(0,0,0,0.35); }
.action.a { right: 6px; top: 30px; background: radial-gradient(circle at 32% 28%, #ff8a7a, #d23b2d); }
.action.b { left: 6px; bottom: 30px; background: radial-gradient(circle at 32% 28%, #ffd66a, #c89322); color: #4a3308; }

/* ============================ Overlays ============================ */
.hidden { display: none !important; }

/* Area toast (map label) */
#area-toast {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: clamp(9px, 2.4vw, 12px);
  letter-spacing: 1px;
  padding: 10px 18px;
  border-radius: 0 0 12px 12px;
  border: 3px solid var(--ui-blue-2);
  border-top: none;
  box-shadow: 0 4px 0 var(--shadow);
  animation: toastIn 0.35s ease;
}
@keyframes toastIn { from { transform: translate(-50%, -120%); } to { transform: translate(-50%, 0); } }

/* Dialogue box */
#dialogue {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(94%, 720px);
  min-height: 86px;
  background: var(--paper);
  border: 6px solid var(--ui-blue-2);
  border-radius: 16px;
  box-shadow: inset 0 0 0 3px var(--ui-blue-line), 0 5px 0 var(--shadow), 0 0 0 3px var(--ui-blue-3);
  padding: 14px 18px 18px;
  color: var(--ink);
}
#dialogue-name {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--ui-blue-2);
  margin-bottom: 8px;
}
#dialogue-text {
  font-size: clamp(20px, 5vw, 28px);
  line-height: 1.05;
  white-space: pre-wrap;
  min-height: 2.1em;
}
#dialogue-cursor {
  position: absolute;
  right: 16px; bottom: 8px;
  color: var(--ui-blue-2);
  font-size: 16px;
  animation: blink 0.8s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Content panel */
#panel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 14, 28, 0.55);
  backdrop-filter: blur(2px);
  padding: 12px;
  animation: fadeIn 0.18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
#panel-window {
  width: min(100%, 680px);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 6px solid var(--ui-blue-2);
  border-radius: 16px;
  box-shadow: inset 0 0 0 3px var(--ui-blue-line), 0 8px 0 var(--shadow), 0 0 0 3px var(--ui-blue-3);
  overflow: hidden;
}
#panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(180deg, var(--ui-blue), var(--ui-blue-2));
  color: #fff;
}
#panel-title { font-family: var(--font-pixel); font-size: clamp(11px, 3vw, 15px); letter-spacing: 1px; text-shadow: 1px 1px 0 var(--ui-blue-3); }
#panel-close {
  border: 2px solid #fff;
  background: rgba(255,255,255,0.15);
  color: #fff;
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}
#panel-close:active { background: rgba(255,255,255,0.35); }
#panel-body {
  padding: 16px 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  color: var(--ink);
  font-size: clamp(18px, 4.4vw, 22px);
  line-height: 1.25;
}
#panel-foot {
  padding: 8px 14px;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--ink-soft);
  border-top: 2px dashed var(--silver);
  background: var(--paper-2);
}
.hint-b {
  display: inline-block;
  background: var(--gold);
  color: #4a3308;
  border-radius: 50%;
  width: 18px; height: 18px;
  text-align: center;
  line-height: 18px;
  margin-right: 6px;
}

/* ---- Panel content building blocks ---- */
.p-section { margin-bottom: 22px; }
.p-lead { font-size: 1.05em; color: var(--ink); margin-bottom: 10px; }
.p-card {
  background: var(--paper-2);
  border: 3px solid var(--silver);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.p-card h3 { font-family: var(--font-pixel); font-size: 12px; color: var(--ui-blue-2); margin-bottom: 6px; line-height: 1.5; }
.p-card .meta { font-size: 0.85em; color: var(--ink-soft); margin-bottom: 8px; }
.p-card ul { margin: 6px 0 0 18px; }
.p-card li { margin-bottom: 4px; }
.tag {
  display: inline-block;
  font-family: var(--font-pixel);
  font-size: 8px;
  background: var(--ui-blue);
  color: #fff;
  padding: 4px 7px;
  border-radius: 6px;
  margin: 3px 4px 0 0;
  letter-spacing: 1px;
}
.p-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ui-blue-2);
  font-size: 1.05em;
  border-bottom: 2px solid transparent;
}
.p-link:hover { border-bottom-color: var(--ui-blue); }
.btn-resume {
  display: inline-block;
  font-family: var(--font-pixel);
  font-size: 11px;
  color: #4a3308;
  background: linear-gradient(180deg, #f3e7bf, var(--gold));
  border: 3px solid var(--gold-2);
  border-radius: 10px;
  padding: 12px 16px;
  text-decoration: none;
  box-shadow: 0 3px 0 var(--gold-2);
  margin-top: 8px;
}
.btn-resume:active { transform: translateY(3px); box-shadow: none; }

/* Gym badges (skills) */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.badge {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  background: var(--paper-2);
  border: 3px solid var(--silver);
  border-radius: 12px;
  padding: 10px 8px;
}
.badge .gem {
  width: 46px; height: 46px;
  margin-bottom: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  border-radius: 12px;
  transform: rotate(45deg);
  box-shadow: inset 0 0 8px rgba(255,255,255,0.5), 0 2px 4px rgba(0,0,0,0.3);
}
.badge .gem span { transform: rotate(-45deg); }
.badge .b-name { font-family: var(--font-pixel); font-size: 9px; line-height: 1.4; color: var(--ink); }
.badge .b-lv { font-size: 0.9em; color: var(--ink-soft); }

/* Trainer card */
.trainer-card {
  background: linear-gradient(135deg, #f0b24a, #e08a2e);
  border: 4px solid #8a5a1a;
  border-radius: 16px;
  padding: 16px;
  color: #3a2408;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.35);
}
.trainer-card.silver { background: linear-gradient(135deg, #dfe6ef, #aeb8c8); border-color: #6a7488; color: #20303f; }
.tc-top { display: flex; justify-content: space-between; align-items: center; font-family: var(--font-pixel); font-size: 11px; margin-bottom: 14px; }
.tc-main { display: flex; gap: 16px; align-items: center; }
.tc-portrait {
  width: 96px; height: 96px;
  background: rgba(255,255,255,0.45);
  border: 3px solid rgba(0,0,0,0.25);
  border-radius: 10px;
  image-rendering: pixelated;
  flex: 0 0 auto;
}
.tc-info { font-size: 1.1em; line-height: 1.6; }
.tc-info .row { display: flex; justify-content: space-between; gap: 18px; }
.tc-info .k { font-family: var(--font-pixel); font-size: 9px; opacity: 0.8; }

/* START menu */
#menu {
  position: absolute;
  top: 10px; right: 10px;
  width: min(54%, 220px);
}
#menu-list {
  list-style: none;
  background: var(--paper);
  border: 5px solid var(--ui-blue-2);
  border-radius: 14px;
  box-shadow: inset 0 0 0 3px var(--ui-blue-line), 0 5px 0 var(--shadow), 0 0 0 3px var(--ui-blue-3);
  overflow: hidden;
}
#menu-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--ink);
  cursor: pointer;
}
#menu-list li .arrow { opacity: 0; color: var(--ui-blue-2); }
#menu-list li.sel { background: var(--ui-blue-line); }
#menu-list li.sel .arrow { opacity: 1; }
#menu-list li:active { background: var(--ui-blue); color: #fff; }

/* ============================ Boot screen ============================ */
#boot {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(120% 80% at 50% 0%, #2a5da0 0%, #15356b 45%, #0a1f44 100%);
  z-index: 30;
  text-align: center;
  padding: 20px;
}
#boot.fade-out { animation: bootOut 0.5s forwards; }
@keyframes bootOut { to { opacity: 0; visibility: hidden; } }
#boot-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; }
#boot-title {
  font-family: var(--font-pixel);
  font-size: clamp(22px, 7vw, 44px);
  color: var(--gold);
  text-shadow: 3px 3px 0 #7a4a12, 6px 6px 0 rgba(0,0,0,0.3);
  letter-spacing: 2px;
}
#boot-sub {
  font-family: var(--font-pixel);
  font-size: clamp(9px, 2.6vw, 13px);
  color: var(--silver);
  letter-spacing: 3px;
}
#boot-sprite {
  width: 96px; height: 96px;
  image-rendering: pixelated;
  margin: 6px 0;
  animation: bob 0.9s ease-in-out infinite alternate;
}
@keyframes bob { to { transform: translateY(-8px); } }
#boot-start {
  font-family: var(--font-pixel);
  font-size: clamp(11px, 3.4vw, 16px);
  color: #fff;
  background: none;
  border: none;
  cursor: pointer;
  letter-spacing: 2px;
  animation: blink 1s steps(1) infinite;
  padding: 8px;
}
#boot-hint {
  font-family: var(--font-pixel);
  font-size: clamp(7px, 2vw, 9px);
  color: rgba(255,255,255,0.65);
  line-height: 1.8;
  max-width: 420px;
}

/* ============================ Desktop bezel ============================ */
@media (min-width: 860px) and (min-height: 640px) {
  #device {
    width: min(94vw, 1000px);
    height: min(94dvh, 760px);
    border-radius: 26px;
    padding: 10px 16px 16px;
    background: linear-gradient(160deg, #21436f, #102543);
    box-shadow: 0 30px 60px rgba(0,0,0,0.6), inset 0 0 0 2px rgba(255,255,255,0.06);
  }
  #device-top-bar { display: flex; }
  #screen-top {
    border-radius: 12px 12px 4px 4px;
    border: 4px solid #06101f;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.5);
  }
  #screen-bottom {
    margin-top: 10px;
    border-radius: 4px 4px 14px 14px;
    border: 4px solid #06101f;
    border-top: 4px solid #06101f;
  }
}

/* On big screens make A/B + dpad a touch smaller to fit nicely */
@media (min-width: 860px) and (min-height: 640px) {
  #dpad, #ab { width: 120px; height: 120px; }
  .action { width: 52px; height: 52px; }
}

/* Hide blinking cursor nicely when not needed handled by JS */
