@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap");

:root {
  --sky-top: #8fd7ff;
  --sky-mid: #bcecff;
  --sky-low: #e2f8ff;
  --sun: #ffd24e;
  --grass: #6ecb4a;
  --grass-dark: #4b9e33;
  --dirt: #8b5a2b;
  --dirt-dark: #5f3b1e;
  --stone: #5d6772;
  --stone-light: #8f9ca8;
  --ink: #171717;
  --paper: #f4f7f9;
  --me: #d6ffd5;
  --bot: #eff4f7;
  --pixel-border: 3px solid #1f1f1f;
  --pixel-shadow: 0 4px 0 #1f1f1f;
  --pad: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "VT323", "Courier New", monospace;
  font-size: 24px;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 38%, var(--sky-low) 100%);
  overflow-x: hidden;
}

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.sun {
  position: absolute;
  top: 26px;
  right: 34px;
  width: 72px;
  height: 72px;
  background: var(--sun);
  border: var(--pixel-border);
  box-shadow: 0 0 0 8px rgba(255, 210, 78, 0.25);
}

.cloud {
  position: absolute;
  height: 26px;
  background: rgba(255, 255, 255, 0.93);
  border: 2px solid rgba(255, 255, 255, 0.6);
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border: inherit;
}

.cloud-a {
  width: 110px;
  top: 76px;
  left: -120px;
  animation: drift-a 24s linear infinite;
}

.cloud-a::before {
  width: 32px;
  height: 20px;
  left: 12px;
  top: -14px;
}

.cloud-a::after {
  width: 40px;
  height: 20px;
  right: 18px;
  top: -14px;
}

.cloud-b {
  width: 130px;
  top: 136px;
  left: -160px;
  opacity: 0.85;
  animation: drift-b 32s linear infinite;
}

.cloud-b::before {
  width: 40px;
  height: 20px;
  left: 22px;
  top: -14px;
}

.cloud-b::after {
  width: 44px;
  height: 20px;
  right: 22px;
  top: -14px;
}

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 23vh;
  min-height: 132px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.11) 0 8px, transparent 8px 16px),
    linear-gradient(180deg, var(--grass) 0 22%, var(--dirt) 22% 100%);
  border-top: 4px solid var(--grass-dark);
}

.ground::before {
  content: "";
  position: absolute;
  inset: 23% 0 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.18)),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.08) 0 8px, transparent 8px 16px);
}

.header,
.study-tools,
.progress,
.chat,
.chips {
  position: relative;
  z-index: 1;
  width: min(980px, calc(100% - 20px));
  margin-left: auto;
  margin-right: auto;
}

.header {
  margin-top: calc(14px + env(safe-area-inset-top));
  padding: 14px;
  background: linear-gradient(180deg, #e9eef3, #dce4ea);
  border: var(--pixel-border);
  box-shadow: var(--pixel-shadow);
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.block-icon {
  width: 24px;
  height: 24px;
  background:
    linear-gradient(180deg, #7ec95a 0 33%, #8b5a2b 33% 100%);
  border: 2px solid #202020;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.2);
}

.title {
  margin: 0;
  font-family: "Press Start 2P", "VT323", monospace;
  font-size: clamp(12px, 2.8vw, 17px);
  line-height: 1.4;
  letter-spacing: 0.02em;
}

.subtitle {
  margin-top: 8px;
  font-size: clamp(20px, 4.3vw, 25px);
  line-height: 1.15;
  color: #2f3d47;
}

.chat {
  margin: 12px auto 0;
  height: calc(100vh - 510px);
  min-height: 280px;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: auto;
  background: linear-gradient(180deg, rgba(244, 247, 249, 0.95), rgba(236, 242, 246, 0.9));
  border: var(--pixel-border);
  box-shadow: var(--pixel-shadow);
}

body.progress-collapsed .chat {
  height: calc(100vh - 390px);
}

.chat:empty::before {
  content: "Start your 11+ study chat. Pick a tool or ask a question.";
  display: block;
  align-self: center;
  text-align: center;
  max-width: 680px;
  color: #4f646f;
  font-size: clamp(22px, 4vw, 25px);
}

.bubble {
  width: min(94%, 760px);
  max-width: 100%;
  margin: 10px 0;
  padding: 10px 12px;
  border: 2px solid #1f1f1f;
  box-shadow: 0 3px 0 #1f1f1f;
  line-height: 1.12;
  font-size: clamp(22px, 4.8vw, 30px);
  white-space: pre-wrap;
  word-break: break-word;
  animation: pop-in 160ms ease-out;
}

.me {
  align-self: center;
  background: linear-gradient(180deg, #e6ffde, var(--me));
}

.bot {
  align-self: center;
  background: linear-gradient(180deg, #ffffff, var(--bot));
}

.eval-row {
  width: min(94%, 760px);
  max-width: 100%;
  margin: -2px 0 10px;
  padding: 6px 8px;
  border: 2px solid #1f1f1f;
  box-shadow: 0 3px 0 #1f1f1f;
  background: linear-gradient(180deg, #f3fbff, #e4f4ff);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-size: clamp(18px, 3.2vw, 22px);
}

.eval-btn {
  cursor: pointer;
  font-family: "VT323", monospace;
  font-size: clamp(18px, 3vw, 22px);
  padding: 4px 8px;
  border: 2px solid #1f1f1f;
  box-shadow: 0 3px 0 #1f1f1f;
}

.eval-btn.good {
  background: linear-gradient(180deg, #d9ffd5, #bbf0b4);
}

.eval-btn.bad {
  background: linear-gradient(180deg, #ffe6cf, #ffc998);
}

.study-tools {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 4px;
}

.study-tools::-webkit-scrollbar {
  height: 8px;
}

.study-tools::-webkit-scrollbar-thumb {
  background: rgba(31, 31, 31, 0.3);
}

.chips {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 0 8px;
}

.chips::-webkit-scrollbar {
  height: 8px;
}

.chips::-webkit-scrollbar-thumb {
  background: rgba(31, 31, 31, 0.3);
}

.chip,
.study-chip,
.send {
  cursor: pointer;
  border: 2px solid #1f1f1f;
  box-shadow: 0 4px 0 #1f1f1f;
  transform: translateY(0);
  transition: transform 90ms ease, box-shadow 90ms ease, filter 90ms ease;
}

.chip:active,
.study-chip:active,
.send:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #1f1f1f;
}

.chip {
  font-family: "VT323", monospace;
  font-size: clamp(22px, 4vw, 25px);
  padding: 6px 12px;
  white-space: nowrap;
  background: linear-gradient(180deg, #ffffff, #e5ebf0);
}

.study-chip {
  font-family: "VT323", monospace;
  font-size: clamp(21px, 3.3vw, 24px);
  padding: 6px 10px;
  white-space: nowrap;
  color: #0d2a39;
  background: linear-gradient(180deg, #d9f5ff, #b6e6ff);
}

.progress {
  margin-top: 6px;
  padding: 8px;
  border: 2px solid #1f1f1f;
  box-shadow: 0 3px 0 #1f1f1f;
  background: linear-gradient(180deg, rgba(233, 245, 255, 0.96), rgba(223, 237, 248, 0.92));
}

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

.progress-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.progress-title {
  font-family: "Press Start 2P", "VT323", monospace;
  font-size: clamp(10px, 2.2vw, 12px);
}

.progress-refresh,
.progress-toggle {
  cursor: pointer;
  font-family: "VT323", monospace;
  font-size: clamp(20px, 3vw, 24px);
  padding: 2px 10px;
  border: 2px solid #1f1f1f;
  box-shadow: 0 3px 0 #1f1f1f;
  background: linear-gradient(180deg, #ffffff, #e8edf2);
}

.progress-toggle {
  min-width: 92px;
}

.progress.collapsed .progress-summary,
.progress.collapsed .progress-row,
.progress.collapsed .progress-card {
  display: none;
}

.progress.collapsed {
  padding-bottom: 6px;
}

.progress-summary {
  margin-top: 6px;
  font-size: clamp(20px, 3.5vw, 24px);
  color: #223440;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.progress-card {
  margin-top: 8px;
  border: 2px solid #1f1f1f;
  background: rgba(255, 255, 255, 0.85);
  padding: 6px;
}

.progress-label {
  font-family: "Press Start 2P", "VT323", monospace;
  font-size: clamp(9px, 2vw, 11px);
  margin-bottom: 6px;
}

.progress-list {
  font-size: clamp(19px, 3.4vw, 24px);
  line-height: 1.1;
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.trend-day {
  border: 2px solid #1f1f1f;
  padding: 4px;
  text-align: center;
  font-size: clamp(14px, 2.2vw, 18px);
  line-height: 1.1;
  background: #e7edf2;
}

.trend-score-strong {
  background: #c8f0c6;
}

.trend-score-mid {
  background: #f8ebbf;
}

.trend-score-low {
  background: #ffd7c8;
}

.heatmap-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.heat-chip {
  border: 2px solid #1f1f1f;
  padding: 2px 8px;
  font-size: clamp(18px, 2.8vw, 22px);
  line-height: 1.1;
}

.heat-l1 {
  background: #ffe0d4;
}

.heat-l2 {
  background: #fff1bf;
}

.heat-l3 {
  background: #d8f4cb;
}

.heat-l4 {
  background: #b5edaf;
}

.bar {
  position: fixed;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: min(980px, calc(100% - 16px));
  bottom: 0;
  margin: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px max(10px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(94, 103, 114, 0.98), rgba(62, 70, 80, 0.98));
  border-top: var(--pixel-border);
  border-left: var(--pixel-border);
  border-right: var(--pixel-border);
  box-shadow: 0 -4px 0 #1f1f1f;
}

.msg {
  flex: 1;
  min-width: 0;
  font-family: "VT323", monospace;
  font-size: clamp(24px, 4.8vw, 30px);
  padding: 8px 10px;
  color: #101010;
  background: #fffef8;
  border: 2px solid #1f1f1f;
  outline: none;
}

.msg:focus {
  box-shadow: inset 0 0 0 2px #6ecb4a;
}

.send {
  font-family: "Press Start 2P", "VT323", monospace;
  font-size: clamp(10px, 2.6vw, 12px);
  padding: 14px 14px;
  color: #1d1400;
  background: linear-gradient(180deg, #ffd65f, #f1af1f);
}

.send:disabled {
  cursor: not-allowed;
  filter: grayscale(0.45);
}

@keyframes pop-in {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes drift-a {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(calc(100vw + 240px));
  }
}

@keyframes drift-b {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(calc(100vw + 300px));
  }
}

@media (min-width: 900px) {
  .header,
  .study-tools,
  .progress,
  .chat,
  .chips,
  .bar {
    width: min(980px, calc(100% - 20px));
  }

  .bar {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(980px, calc(100% - 20px));
  }

  .chat {
    height: calc(100vh - 470px);
  }

  body.progress-collapsed .chat {
    height: calc(100vh - 350px);
  }
}

@media (max-width: 680px) {
  .header,
  .study-tools,
  .progress,
  .chat {
    width: calc(100% - 56px);
  }

  .chips,
  .bar {
    width: calc(100% - 16px);
  }

  .header {
    margin-top: calc(6px + env(safe-area-inset-top));
    padding: 10px;
  }

  .title {
    font-size: clamp(11px, 5.3vw, 14px);
  }

  .subtitle {
    font-size: clamp(16px, 6.4vw, 21px);
    line-height: 1.2;
  }

  .sun {
    width: 46px;
    height: 46px;
    right: 8px;
    top: calc(env(safe-area-inset-top) + 10px);
    box-shadow: 0 0 0 6px rgba(255, 210, 78, 0.22);
  }

  .chat {
    margin-top: 8px;
    height: clamp(220px, calc(100vh - 520px), 620px);
    height: clamp(220px, calc(100dvh - 520px), 620px);
    min-height: 220px;
    max-height: 620px;
    margin-bottom: 132px;
    padding: 8px;
  }

  .chat:empty::before {
    max-width: 96%;
    font-size: clamp(18px, 6.2vw, 24px);
  }

  .bubble {
    width: min(96%, 760px);
    font-size: clamp(20px, 6.6vw, 27px);
  }

  .chips {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(86px + env(safe-area-inset-bottom));
    z-index: 5;
    gap: 6px;
    justify-content: center;
    overflow-x: auto;
    padding: 6px;
    border: 2px solid #1f1f1f;
    box-shadow: 0 3px 0 #1f1f1f;
    background: rgba(234, 243, 250, 0.92);
  }

  .study-tools {
    padding-top: 8px;
    padding-bottom: 4px;
    gap: 6px;
  }

  .progress {
    margin-top: 4px;
    padding: 6px;
  }

  .progress-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .trend-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .chip {
    font-size: clamp(13px, 3.8vw, 16px);
    padding: 4px 8px;
  }

  .study-chip {
    font-size: clamp(13px, 3.8vw, 16px);
    padding: 4px 8px;
  }

  .bar {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: calc(100% - 16px);
    bottom: 0;
    z-index: 6;
    padding: 8px;
  }

  .msg {
    font-size: clamp(20px, 6vw, 26px);
  }

  .send {
    min-width: 90px;
    padding: 12px 10px;
  }

  body.progress-collapsed .chat {
    height: clamp(220px, calc(100vh - 420px), 620px);
    height: clamp(220px, calc(100dvh - 420px), 620px);
  }
}

@media (max-width: 440px) {
  .chip {
    font-size: 14px;
  }

  .study-chip {
    font-size: 14px;
  }

  .chat {
    height: clamp(220px, calc(100vh - 560px), 620px);
    height: clamp(220px, calc(100dvh - 560px), 620px);
    min-height: 220px;
  }

  body.progress-collapsed .chat {
    height: clamp(220px, calc(100vh - 460px), 620px);
    height: clamp(220px, calc(100dvh - 460px), 620px);
  }
}
