:root {
  --bg: #f4f1e8;
  --panel: #fffaf0;
  --line: #2b2b2b;
  --muted: #6b6b6b;
  --accent: #375f3a;
}
* { box-sizing: border-box; }
html, body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: #1e1e1e;
  font-family: Arial, Helvetica, sans-serif;
  overflow: hidden;
}
.wrap {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  height: 100dvh;
  padding: 10px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
.card {
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 10px;
  border-radius: 10px;
}
.stat-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}
.stat-value {
  font-size: 19px;
  font-weight: bold;
}
.small {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
}
.hidden-run {
  display: none;
}
.hidden-dev {
  display: none;
}
.top-tools {
  display: flex;
  gap: 8px;
}
.top-tools button {
  flex: 1;
  padding: 7px 8px;
  border: 2px solid var(--line);
  background: #f7f0dc;
  border-radius: 8px;
  font-size: 12px;
  font-weight: bold;
}
.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}
.hud .card {
  padding: 6px 7px;
  border-radius: 8px;
}
.hud .stat-label {
  font-size: 9px;
  letter-spacing: 0.03em;
  margin-bottom: 2px;
}
.hud .stat-value {
  font-size: 14px;
  line-height: 1.1;
}
.screens {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.screen {
  display: none;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.screen.active {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.game-home button,
.shop button,
.bottom-nav button,
.run-end-overlay button {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  background: #f7f0dc;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
}
.game-home button.primary-go,
.shop button.primary-go {
  background: #4f8d55;
  color: #f3fff2;
  border-color: #2f5d34;
}
.level-selector {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.level-selector button {
  margin-top: 0;
  padding: 8px 6px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #f7f0dc;
  font-size: 18px;
  line-height: 1;
  font-weight: bold;
}
.level-label {
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
  background: #f9f3e4;
  font-size: 13px;
  font-weight: 700;
}
.shop-stage {
  display: grid;
  grid-auto-rows: min-content;
  gap: 6px;
}
#shopScreen {
  min-height: 0;
}
#shopScreen.active {
  overflow: hidden;
}
#shopPanel {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 100%;
  overflow-y: auto;
  gap: 6px;
  padding-right: 8px;
}
.shop-separator {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #ab9a77;
}
.shop-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.shop-section-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}
.shop-section-toggle {
  width: 100%;
  margin-top: 0;
  border: 1px solid #b8aa8d;
  border-radius: 8px;
  padding: 8px 10px;
  background: #f7f0dc;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
}
.shop-section-toggle:active {
  background: #efe5ca;
}
.shop-section-toggle:focus-visible {
  outline: 2px solid #7e6d43;
  outline-offset: 1px;
}
.shop-section-title {
  font-size: 13px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 700;
}
.shop-section-icon {
  font-size: 14px;
  color: #4b4334;
}
.shop-section-body {
  display: grid;
  grid-auto-rows: min-content;
  gap: 6px;
}
.shop-section-body.collapsed {
  display: none;
}
.message {
  min-height: 56px;
  line-height: 1.35;
}
.canvas-wrap {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}
canvas {
  background: #d9ccb1;
  border: 2px solid var(--line);
  border-radius: 12px;
  display: block;
  z-index: 1;
}
.end-run-btn {
  display: none;
}
.run-end-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  background: rgba(14, 12, 10, 0.62);
  border-radius: 12px;
  z-index: 30;
}
.run-end-overlay.visible {
  display: flex;
}
.run-end-title {
  font-size: 34px;
  font-weight: 800;
  color: #fff7da;
  text-shadow: 0 2px 0 #000;
}
.floating-text {
  position: absolute;
  pointer-events: none;
  transform: translate(-50%, -50%);
  font-weight: bold;
  font-size: 20px;
  color: #fff8dc;
  text-shadow: 0 2px 0 #000, 0 0 8px rgba(0,0,0,0.35);
  z-index: 20;
  white-space: nowrap;
}
.journal-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#journalScreen {
  min-height: 0;
}
#journalScreen .journal {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  min-height: 100%;
}
#journalScreen .journal-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}
.journal-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.journal-section-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
}
.journal-section-toggle {
  width: 100%;
  border: 1px solid #b8aa8d;
  border-radius: 8px;
  padding: 8px 10px;
  background: #f7f0dc;
  cursor: pointer;
  text-align: left;
}
.journal-section-toggle:active {
  background: #efe5ca;
}
.journal-section-toggle:focus-visible {
  outline: 2px solid #7e6d43;
  outline-offset: 1px;
}
.journal-section-title {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.journal-section-count {
  font-size: 12px;
  color: var(--muted);
}
.journal-toggle-icon {
  font-size: 14px;
  color: #4b4334;
}
.journal-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.journal-list.collapsed {
  display: none;
}
.bone-row {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 8px;
  align-items: center;
}
.bone-row.unknown {
  opacity: 0.92;
}
.bone-row-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.bone-title {
  font-size: 13px;
  font-weight: bold;
}
.bone-row.new-bone {
  border-color: #f0c84c;
  box-shadow: 0 0 0 2px rgba(240,200,76,0.35), 0 0 12px rgba(240,200,76,0.65);
  animation: newBoneGlow 1.3s ease-in-out infinite alternate;
}
.preview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  width: 84px;
  height: 84px;
  margin: 0;
}
.preview-cell {
  border: 1px solid #222;
  background: #eadcbf;
}
.preview-cell.filled {
  background: #b39a6a;
  border-color: #2b2b2b;
}
.preview-cell.hidden { background: #111; }
.tag-row {
  font-size: 12px;
  color: var(--muted);
}
.journal-empty {
  border: 2px dashed #a6987b;
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  color: var(--muted);
  background: #f6efde;
}
.bottom-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.bottom-nav button {
  margin-top: 0;
  padding: 11px 6px;
}
.bottom-nav button.active {
  background: #4f8d55;
  color: #f3fff2;
  border-color: #2f5d34;
}
.bottom-nav button:disabled,
.shop button:disabled,
.game-home button:disabled,
.top-tools button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
@keyframes messageFlash {
  0% { border-color:#2b2b2b; box-shadow:0 0 0 0 rgba(255,215,0,0); }
  50% { border-color:#ffd54a; box-shadow:0 0 10px 2px rgba(255,213,74,0.8); }
  100% { border-color:#2b2b2b; box-shadow:0 0 0 0 rgba(255,215,0,0); }
}
.message.flash {
  animation: messageFlash 0.6s ease;
}
@keyframes newBoneGlow {
  0% { box-shadow: 0 0 0 2px rgba(240,200,76,0.22), 0 0 10px rgba(240,200,76,0.40); }
  100% { box-shadow: 0 0 0 2px rgba(240,200,76,0.45), 0 0 18px rgba(240,200,76,0.85); }
}
