/* 레이아웃: 초록 종합장 표지를 넘기면 깍두기공책 그림일기가 나온다. 밝은 공책 한 가지 모습만 쓴다. */
:root {
  --paper: #eef4e4;
  --grid: #c5dcc0;
  --cover: #2f6b5a;
  --cover-deep: #24564a;
  --label: #fbfdf6;
  --ink: #2b3431;
  --soft: #5a6a63;
  --stamp: #d03a2f;
  --crayon: #2c63c4;
  --yellow: #f4c430;
  --shade: rgba(20, 30, 28, 0.72);
  --grade-c: #6d7a73;
  --grade-b: #2c63c4;
  --grade-a: #7a3fb5;
  --grade-s: #c9660c;
  --grade-ss: #c4162b;
  --hand: "Gaegu", "Malgun Gothic", cursive;
  --title: "Gamja Flower", "Gaegu", "Malgun Gothic", cursive;
  --body: "Gowun Dodum", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--cover);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.7;
}
[hidden] { display: none !important; }

.screen {
  min-height: 100%;
  padding-block: 24px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 28px;
}

/* 표지 */
.cover {
  background: repeating-linear-gradient(115deg, var(--cover) 0 7px, var(--cover-deep) 7px 8px);
}
.label-card {
  width: min(100%, 460px);
  padding: 24px clamp(20px, 6vw, 36px) 20px;
  background: var(--label);
  border: 3px double var(--cover-deep);
  display: grid;
  gap: 16px;
  transform: rotate(-0.6deg);
}
.label-tag {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.3em;
  color: var(--soft);
  text-align: center;
}
h1 {
  margin: 0;
  font-family: var(--title);
  font-weight: 400;
  font-size: clamp(40px, 11vw, 60px);
  line-height: 1.15;
  text-align: center;
  color: var(--crayon);
  text-wrap: balance;
}
.fields { margin: 0; display: grid; }
.fields div {
  display: grid;
  grid-template-columns: 5em minmax(0, 1fr);
  align-items: baseline;
  padding-block: 2px;
  border-bottom: 1px solid var(--grid);
}
.fields dt { color: var(--soft); font-size: 14px; }
.fields dd { margin: 0; font-family: var(--hand); font-size: 22px; font-weight: 700; }
.cover-actions { display: grid; justify-items: center; gap: 8px; }

/* 버튼 */
.btn {
  min-width: 160px;
  min-height: 48px;
  padding: 8px 28px;
  border: 3px solid var(--ink);
  border-radius: 8px 12px 9px 13px;
  background: var(--yellow);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 3px 4px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 5px 0 var(--ink); }
.btn:active { transform: translate(3px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn-text {
  min-height: 44px;
  padding: 4px 12px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.cover .btn-text { color: var(--label); }
button:focus-visible { outline: 3px solid var(--crayon); outline-offset: 3px; }

/* 그림일기 */
.sheet {
  width: min(100%, 640px);
  padding: 16px clamp(14px, 4vw, 28px) 20px;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  border-radius: 4px;
  display: grid;
  gap: 12px;
}
#intro .sheet { width: min(calc(100vw - 32px), 640px); }
.diary-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--hand);
  font-size: 20px;
  font-weight: 700;
}
.count { color: var(--soft); font-variant-numeric: tabular-nums; }
.picture {
  position: relative;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  border: 3px solid var(--ink);
  background: var(--label);
  overflow: hidden;
}
.picture canvas { display: block; width: 100%; height: 100%; }
.diary-text {
  margin: 0;
  min-height: 5.4em;
  padding-inline: 6px;
  font-family: var(--hand);
  font-size: 23px;
  font-weight: 700;
  line-height: 1.35;
  word-break: keep-all;
  background: var(--paper);
}
.diary-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.diary-foot .btn { margin-left: auto; }

/* 눈꺼풀 연출 */
.lids { position: absolute; inset: 0; pointer-events: none; }
.lids i {
  position: absolute;
  left: -10%;
  right: -10%;
  height: 56%;
  background: #0d0f12;
}
.lids i:first-child { top: 0; border-radius: 0 0 50% 50% / 0 0 24% 24%; animation: lid-top 2.1s ease-in-out forwards; }
.lids i:last-child { bottom: 0; border-radius: 50% 50% 0 0 / 24% 24% 0 0; animation: lid-bottom 2.1s ease-in-out forwards; }
@keyframes lid-top {
  0%, 12% { transform: translateY(0); }
  32% { transform: translateY(-34%); }
  46% { transform: translateY(0); }
  100% { transform: translateY(-110%); }
}
@keyframes lid-bottom {
  0%, 12% { transform: translateY(0); }
  32% { transform: translateY(34%); }
  46% { transform: translateY(0); }
  100% { transform: translateY(110%); }
}

/* 메인 화면 */
#game .sheet { width: min(calc(100vw - 32px), 640px); }
.clock { display: grid; gap: 4px; }
.clock-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.age-now {
  margin: 0;
  font-family: var(--title);
  font-size: clamp(40px, 11vw, 52px);
  line-height: 1.1;
  color: var(--crayon);
  font-variant-numeric: tabular-nums;
}
.clock-sub {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 12px;
  color: var(--soft);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.month-bar, .ruler-track {
  position: relative;
  border: 2px solid var(--ink);
  background: var(--label);
}
.month-bar { height: 10px; overflow: hidden; }
.month-bar i, .ruler-track i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
}
.month-bar i { background: var(--yellow); }
.ruler { display: grid; gap: 2px; }
.ruler-track { height: 16px; }
.ruler-track i { background: var(--crayon); }
.ruler-track b {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 3px;
  margin-left: -1px;
  background: var(--stamp);
}
.ruler-ages {
  display: flex;
  justify-content: space-between;
  color: var(--soft);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.wallet {
  padding: 10px 14px;
  border: 3px solid var(--ink);
  background: var(--label);
  display: grid;
  gap: 8px;
}
.money { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.money span { flex: none; color: var(--soft); }
.money small { font-size: 14px; }
.money b { color: var(--ink); font-variant-numeric: tabular-nums; }
.money strong {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
  font-family: var(--hand);
  font-size: 32px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stats {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  border-top: 1px solid var(--grid);
  padding-top: 8px;
}
.stats div { min-width: 0; text-align: center; }
.stats dt { color: var(--soft); font-size: 14px; }
.stats dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: var(--hand);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stage {
  display: block;
  width: 100%;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.stage:disabled { cursor: default; }
.stage:active:not(:disabled) canvas { transform: scale(1.015); }
.stage-hint {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 0 10px;
  background: var(--label);
  border: 2px solid var(--ink);
  border-radius: 6px;
  font-family: var(--hand);
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}
.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--hand);
  font-size: 24px;
  font-weight: 700;
  color: var(--stamp);
  text-shadow: 1px 1px 0 var(--label), -1px -1px 0 var(--label);
  pointer-events: none;
  white-space: nowrap;
  animation: rise 0.7s ease-out forwards;
}
@keyframes rise {
  to { transform: translate(-50%, -260%); opacity: 0; }
}
.income {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 12px;
  padding-inline: 6px;
  background: var(--paper);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.panel { display: grid; gap: 6px; }
.panel h2 {
  margin: 0;
  padding-inline: 6px;
  justify-self: start;
  font-family: var(--hand);
  font-size: 22px;
  line-height: 1.3;
  background: var(--paper);
}
.focus { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.focus-btn {
  min-width: 0;
  min-height: 44px;
  padding: 4px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--label);
  color: var(--ink);
  font: inherit;
  word-break: keep-all;
  line-height: 1.25;
  cursor: pointer;
}
.focus-btn[aria-pressed="true"] { background: var(--crayon); color: var(--label); font-weight: 700; }
.earners { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.earner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 2px solid var(--ink);
  background: var(--label);
}
.earner.locked { border-style: dashed; color: var(--soft); }
.earner-info { min-width: 0; display: grid; }
.earner-info span { font-size: 14px; color: var(--soft); word-break: keep-all; }
.earner-info small { font-size: 13px; line-height: 1.4; color: var(--soft); word-break: keep-all; }
.needs { display: flex; flex-wrap: wrap; gap: 4px; margin-block: 4px; }
.needs i {
  padding: 0 6px;
  border: 1px solid var(--stamp);
  border-radius: 4px;
  color: var(--stamp);
  font-size: 13px;
  font-style: normal;
  font-variant-numeric: tabular-nums;
}
.needs i.met { border-color: var(--cover); color: var(--cover); }
.tag {
  display: inline-block;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--grid);
  color: var(--ink);
  font-size: 12px;
  font-style: normal;
  font-weight: 400;
  vertical-align: 1px;
}
.tag.dark { background: var(--ink); color: var(--label); }
.job-now {
  padding: 8px 10px;
  border: 2px solid var(--ink);
  background: var(--label);
  display: grid;
}
.job-now strong { font-family: var(--hand); font-size: 24px; line-height: 1.25; }
.job-now span { font-size: 14px; color: var(--soft); word-break: keep-all; }
.job-last { padding: 8px 10px; background: var(--label); border: 2px solid var(--ink); }
.buy {
  flex: none;
  max-width: 48%;
  min-height: 44px;
  padding: 4px 10px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--yellow);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  word-break: keep-all;
  line-height: 1.25;
  cursor: pointer;
}
.buy:disabled { background: var(--paper); color: var(--soft); cursor: not-allowed; }
/* 직업 등급 */
.grade {
  display: inline-block;
  min-width: 1.7em;
  padding: 0 4px;
  border-radius: 4px;
  color: var(--label);
  font-family: var(--body);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  text-align: center;
  vertical-align: 1px;
}
.grade-C { background: var(--grade-c); }
.grade-B { background: var(--grade-b); }
.grade-A { background: var(--grade-a); }
.grade-S { background: var(--grade-s); }
.grade-SS { background: var(--grade-ss); }
.odds { display: grid; gap: 4px; }
.odds-bar { display: flex; height: 16px; border: 2px solid var(--ink); background: var(--label); overflow: hidden; }
.odds-bar i { display: block; min-width: 2px; }
.odds-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  padding-inline: 6px;
  background: var(--paper);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* 뽑기와 스카우트 팝업 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding-block: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--shade);
  display: grid;
  align-items: safe center;
  justify-items: center;
  overflow-y: auto;
}
.modal-box {
  width: min(100%, 620px);
  padding: 20px clamp(14px, 4vw, 24px);
  border: 3px solid var(--ink);
  background: var(--paper);
  display: grid;
  gap: 12px;
}
.modal-box h2 {
  margin: 0;
  font-family: var(--title);
  font-size: 32px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--crayon);
  text-wrap: balance;
}
.modal-tag { margin: 0; font-size: 14px; letter-spacing: 0.08em; color: var(--soft); }
.modal-tag.scout { color: var(--stamp); font-weight: 700; }
.modal-text { margin: 0; font-family: var(--hand); font-size: 22px; font-weight: 700; line-height: 1.4; word-break: keep-all; }
.modal-offer { margin: 0; font-size: 18px; font-weight: 700; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.modal-actions .btn { margin-left: auto; }
.cards { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.card {
  width: 100%;
  height: 100%;
  min-height: 190px;
  padding: 8px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--label);
  color: var(--ink);
  font: inherit;
  text-align: left;
  display: grid;
  align-content: start;
  gap: 4px;
  cursor: pointer;
  animation: flip 0.45s ease-out backwards;
}
.cards li:nth-child(2) .card { animation-delay: 0.15s; }
.cards li:nth-child(3) .card { animation-delay: 0.3s; }
@keyframes flip {
  from { transform: rotateY(90deg); }
}
.card:hover { transform: translateY(-2px); }
.card strong { font-size: 17px; line-height: 1.3; word-break: keep-all; }
.card-grade {
  justify-self: start;
  padding: 0 6px;
  border-radius: 4px;
  color: var(--label);
  font-size: 13px;
  font-weight: 700;
}
.card-C { border-color: var(--grade-c); } .card-C .card-grade { background: var(--grade-c); }
.card-B { border-color: var(--grade-b); } .card-B .card-grade { background: var(--grade-b); }
.card-A { border-color: var(--grade-a); } .card-A .card-grade { background: var(--grade-a); }
.card-S { border-color: var(--grade-s); } .card-S .card-grade { background: var(--grade-s); }
.card-SS { border-color: var(--grade-ss); box-shadow: 0 0 0 3px var(--yellow); } .card-SS .card-grade { background: var(--grade-ss); }
.card-desc { font-size: 13px; line-height: 1.4; color: var(--soft); word-break: keep-all; }
.card-pay { font-size: 13px; line-height: 1.4; font-weight: 700; font-variant-numeric: tabular-nums; }
.btn-small {
  flex: 1 1 140px;
  min-height: 48px;
  padding: 4px 10px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--label);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
}
.btn-small small { font-weight: 400; color: var(--soft); }
.btn-small:disabled { background: var(--paper); color: var(--soft); cursor: not-allowed; }

/* 휴대폰에서는 터치 화면을 줄여 할 일 버튼까지 한 화면에 넣는다. */
@media (max-width: 640px) {
  .stage { aspect-ratio: 5 / 2; }
  .stage canvas { object-fit: cover; }
  .stats dt { font-size: 13px; }
  .stats dd { font-size: 19px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .card { min-height: 0; }
}
.game-end { display: grid; justify-items: center; gap: 8px; text-align: center; }
.game-end .diary-text { min-height: 0; }
.note { margin: 0; padding-inline: 6px; color: var(--soft); background: var(--paper); }

@media (prefers-reduced-motion: reduce) {
  .lids { display: none; }
  .btn { transition: none; }
  .float, .card { animation: none; }
}
