:root {
  color-scheme: light;
  --bg: #e9edf2;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #6f7b8b;
  --line: #e7ebf0;
  --soft: #f5f7fa;
  --blue: #12a8f4;
  --blue-soft: #dff4ff;
  --amber: #ff9f1c;
  --amber-soft: #fff0d8;
  --rose: #ff4f8b;
  --green: #20b486;
  --shadow: 0 28px 60px rgba(26, 39, 61, .22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  display: block;
  background:
    radial-gradient(circle at 16% 14%, rgba(18, 168, 244, .16), transparent 32%),
    radial-gradient(circle at 86% 82%, rgba(255, 159, 28, .14), transparent 28%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.phone-shell {
  /* 세로가 커지면 가로도 같이 키움 */
  width: min(100vw, clamp(360px, 72dvh, 720px));
  height: 100dvh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0;
  display: block;
}

.app {
  position: relative;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 0;
  background: var(--panel);
  box-shadow: none;
}

.topbar {
  flex: 0 0 auto;
  height: 64px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(16px);
  z-index: 3;
  position: relative;
}

.title-block {
  text-align: center;
  line-height: 1.1;
}

.title-block span {
  display: block;
  margin-bottom: 4px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
}

.title-block h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  color: #3a4656;
  font-size: 24px;
  line-height: 1;
}

.icon-btn:active,
.tool-row:active,
.calc-key:active,
.primary-action:active {
  transform: scale(.97);
}

.favorite-btn.active {
  color: var(--amber);
}

.content {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  display: flex;
  flex-direction: column;
}

.drawer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.drawer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(21, 24, 30, .52);
  opacity: 0;
  transition: opacity .22s ease;
}

.drawer.open {
  pointer-events: auto;
}

.drawer.open::after {
  opacity: 1;
}

.drawer-panel {
  position: relative;
  z-index: 2;
  width: 79%;
  height: 100%;
  overflow-y: auto;
  background: #fff;
  transform: translateX(-100%);
  transition: transform .24s ease;
  box-shadow: 18px 0 45px rgba(16, 24, 40, .18);
}

.drawer.open .drawer-panel {
  transform: translateX(0);
}

.drawer-head {
  height: 66px;
  padding: 0 12px 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #303030;
  color: #fff;
}

.drawer-head h2 {
  margin: 0;
  font-size: 17px;
}

.drawer-head .icon-btn {
  color: #fff;
}

.drawer-summary {
  margin: 16px 18px 0;
  padding: 12px 13px;
  border-radius: 8px;
  background: linear-gradient(135deg, #eef9ff, #fff7eb);
  border: 1px solid #e6edf4;
}

.drawer-summary strong {
  display: block;
  color: #1c2b3d;
  font-size: 14px;
  font-weight: 900;
}

.drawer-summary span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.mini-game-box {
  margin: 12px 18px 0;
}

.mini-toggle {
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 8px;
  padding: 0 13px;
  background: #24262d;
  color: #fff;
  font-weight: 900;
}

.mini-toggle strong {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
  font-size: 12px;
}

.mini-list {
  display: none;
  gap: 8px;
  padding-top: 9px;
}

.mini-list.open {
  display: grid;
}

.mini-list .tool-row {
  background: #fff8ec;
}

.search-wrap {
  display: grid;
  gap: 8px;
  padding: 18px 18px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 13px;
  outline: none;
  background: var(--soft);
}

.tool-section,
.category {
  padding: 10px 18px;
}

.tool-section h3,
.category h3 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--blue);
  color: #3d5168;
  font-size: 13px;
  font-weight: 900;
}

.tool-list {
  display: grid;
  gap: 8px;
}

.tool-row {
  width: 100%;
  min-height: 44px;
  display: grid;
  grid-template-columns: 1fr 28px;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  padding: 10px 9px;
  background: #fff;
  color: #364355;
  text-align: left;
}

.tool-row.active {
  background: var(--blue-soft);
  color: #0795df;
  font-weight: 900;
}

.tool-row .heart {
  color: #cbbbd8;
  text-align: center;
}

.tool-row.favorite .heart {
  color: var(--rose);
}

.calculator-view {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
}

/* 설명은 첫 화면 밖 — 스크롤해야 보임 */
.calculator-view > .info-card {
  flex: 0 0 auto;
  margin: 32px 20px 48px;
  max-height: none;
  overflow: visible;
}

.standard-display {
  flex: 0 0 auto;
  min-height: clamp(96px, 14dvh, 150px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: clamp(12px, 2dvh, 22px) clamp(16px, 3vw, 28px);
  text-align: right;
}

.formula {
  min-height: 22px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: clamp(14px, 2.2dvh, 16px);
  overflow-wrap: anywhere;
}

.display-value {
  min-height: 48px;
  color: #0d1723;
  font-size: clamp(40px, 8dvh, 64px);
  font-weight: 500;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

/* 첫 화면에서 키패드가 남은 높이를 차지 → 설명은 아래로 밀림 */
.keypad {
  flex: 1 0 auto;
  min-height: calc(100dvh - 64px - clamp(96px, 14dvh, 150px));
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(10px, 1.8dvh, 18px);
  padding: clamp(12px, 2.5dvh, 28px) clamp(16px, 3vw, 32px)
    clamp(16px, 3dvh, 28px);
  min-width: 0;
  background: #f3f6f9;
  align-content: center;
  justify-items: center;
}

.calc-key {
  justify-self: center;
  align-self: center;
  box-sizing: border-box;
  width: min(100%, clamp(58px, 12dvh, 100px));
  height: auto;
  aspect-ratio: 1 / 1;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  color: #172130;
  box-shadow: 0 5px 12px rgba(22, 30, 46, .08);
  font-size: clamp(20px, 3.4dvh, 30px);
  font-weight: 650;
  line-height: 1;
}

.calc-key.utility {
  color: var(--blue);
  background: #f7fbff;
}

.calc-key.operator {
  color: #ff8500;
  background: var(--amber-soft);
}

.calc-key.equals {
  color: #fff;
  background: #ff8a00;
}

.tool-view {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.hero-result,
.form-card,
.info-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(27, 39, 58, .05);
}

.hero-result {
  padding: 18px;
  background: linear-gradient(135deg, #f8fcff, #fff9f0);
}

.result-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.result-value {
  margin-top: 7px;
  color: #101927;
  font-size: 30px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.result-note {
  margin-top: 8px;
  color: #617084;
  font-size: 13px;
  line-height: 1.45;
}

.form-card,
.info-card {
  padding: 16px;
}

.field-grid {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: #48586c;
  font-size: 12px;
  font-weight: 900;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d9e0e8;
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  background: #fbfcfe;
  color: #162131;
}

.field input:focus,
.field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(18, 168, 244, .14);
}

.primary-action {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  border-radius: 8px;
  background: #24262d;
  color: #fff;
  font-weight: 900;
}

.mini-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mini-actions .primary-action {
  margin-top: 14px;
}

.ghost-action {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  border-radius: 8px;
  border: 1px solid #d9e0e8;
  background: #fff;
  color: #2f3b4c;
  font-weight: 900;
}

.choice-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.choice-btn {
  min-height: 54px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: #087fc0;
  font-weight: 900;
}

.choice-btn:disabled,
.primary-action:disabled {
  opacity: .65;
  cursor: wait;
}

.countdown-display {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #24262d;
  color: #fff;
  font-size: 24px;
  font-weight: 900;
}

.rps-stage {
  display: grid;
  grid-template-columns: 1fr 44px 1fr;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

.rps-hand {
  min-height: 120px;
  display: grid;
  place-items: center;
  gap: 5px;
  border-radius: 8px;
  background: #f7f9fc;
  border: 1px solid #e4e9f0;
}

.rps-hand strong {
  font-size: 54px;
  line-height: 1;
}

.rps-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.rps-versus {
  text-align: center;
  color: var(--rose);
  font-size: 13px;
  font-weight: 900;
}

.shake {
  animation: handShake .18s ease-in-out infinite alternate;
}

.dice-stage {
  min-height: 92px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 8px;
  background: #f7f9fc;
  border: 1px solid #e4e9f0;
}

.dice-cube {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #fff;
  color: #24262d;
  box-shadow: 0 8px 18px rgba(22, 30, 46, .12);
  font-size: 30px;
  font-weight: 900;
}

.dice-cube.rolling {
  animation: diceRoll .18s linear infinite;
  background: var(--amber-soft);
  color: #ff8500;
}

.ball-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.number-ball {
  min-width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #24262d;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.bonus-ball {
  background: #ff8a00;
}

.lotto-machine {
  position: relative;
  min-height: 150px;
  margin-bottom: 14px;
  border-radius: 18px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #ffffff 0%, #eef6ff 52%, #d7e8f7 100%);
  border: 1px solid #dbe7f2;
}

.lotto-drum {
  position: absolute;
  left: 50%;
  top: 18px;
  width: 130px;
  height: 92px;
  transform: translateX(-50%);
  border-radius: 50%;
  border: 8px solid rgba(18, 168, 244, .28);
  background: rgba(255, 255, 255, .58);
}

.lotto-drum.spin {
  animation: drumSpin .45s linear infinite;
}

.lotto-mini-ball {
  position: absolute;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ffcc4d;
  color: #24262d;
  font-size: 10px;
  font-weight: 900;
  box-shadow: 0 5px 10px rgba(20, 30, 44, .14);
}

.lotto-mini-ball:nth-child(1) { left: 24px; top: 36px; }
.lotto-mini-ball:nth-child(2) { left: 52px; top: 20px; }
.lotto-mini-ball:nth-child(3) { left: 82px; top: 42px; }
.lotto-mini-ball:nth-child(4) { left: 42px; top: 62px; }
.lotto-mini-ball:nth-child(5) { left: 74px; top: 68px; }

.lotto-drum.spin .lotto-mini-ball {
  animation: ballBounce .32s ease-in-out infinite alternate;
}

.lotto-slot {
  position: absolute;
  left: 50%;
  bottom: 16px;
  width: 130px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: #24262d;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.game-board {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.mine-grid,
.ttt-grid {
  display: grid;
  gap: 6px;
  justify-content: center;
}

.mine-grid {
  grid-template-columns: repeat(5, 42px);
}

.ttt-grid {
  grid-template-columns: repeat(3, 62px);
}

.mine-cell,
.ttt-cell {
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef4fa;
  color: #263447;
  font-weight: 900;
}

.mine-cell {
  width: 42px;
  height: 42px;
}

.ttt-cell {
  width: 62px;
  height: 62px;
  font-size: 28px;
}

.slot-window {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.slot-reel {
  min-height: 70px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f7f9fc;
  border: 1px solid #e4e9f0;
  font-size: 34px;
}

.slot-reel.spin {
  animation: slotSpin .16s linear infinite alternate;
}

@keyframes handShake {
  from {
    transform: translateY(0) rotate(-5deg);
  }

  to {
    transform: translateY(-8px) rotate(5deg);
  }
}

@keyframes diceRoll {
  from {
    transform: rotate(0deg) scale(.92);
  }

  to {
    transform: rotate(24deg) scale(1.05);
  }
}

@keyframes drumSpin {
  from {
    transform: translateX(-50%) rotate(0deg);
  }

  to {
    transform: translateX(-50%) rotate(360deg);
  }
}

@keyframes ballBounce {
  from {
    transform: translateY(-6px);
  }

  to {
    transform: translateY(8px);
  }
}

@keyframes slotSpin {
  from {
    transform: translateY(-5px);
  }

  to {
    transform: translateY(5px);
  }
}

.info-card h2 {
  margin: 0 0 10px;
  font-size: 1.0625rem;
  font-weight: 800;
  color: #101927;
}

.info-card p {
  margin: 0;
  color: #3d4b5c;
  font-size: 0.9875rem;
  line-height: 1.65;
}

.tip-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.tip {
  padding: 11px 12px;
  border-radius: 8px;
  background: #f5f8fb;
  color: #3d4b5c;
  font-size: 0.9375rem;
  line-height: 1.55;
}

.empty {
  padding: 12px 10px;
  border-radius: 8px;
  background: #f7f9fc;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

@media (min-width: 900px) {
  .phone-shell {
    width: min(100vw, clamp(480px, 75dvh, 760px));
  }

  .calc-key {
    width: min(100%, clamp(64px, 11dvh, 108px));
    font-size: clamp(22px, 3.2dvh, 32px);
  }

  .info-card {
    padding: 16px 18px;
  }

  .info-card h2 {
    font-size: 1.0625rem;
  }

  .info-card p,
  .tip {
    font-size: 0.9875rem;
  }
}

@media (max-width: 600px) {
  :root {
    --app-safe-top: max(env(safe-area-inset-top, 0px), 0px);
    --app-safe-bottom: max(env(safe-area-inset-bottom, 0px), 0px);
  }

  body {
    background: #fff;
  }

  .phone-shell {
    width: 100vw;
  }

  .topbar {
    height: calc(64px + var(--app-safe-top));
    padding: var(--app-safe-top) 10px 0;
  }

  .drawer-head {
    height: calc(66px + var(--app-safe-top));
    padding: var(--app-safe-top) 12px 0 22px;
  }

  .keypad {
    min-height: calc(
      100dvh - 64px - var(--app-safe-top) - clamp(96px, 14dvh, 150px)
    );
    gap: clamp(8px, 2vw, 12px);
    padding: 12px clamp(12px, 4vw, 18px)
      calc(12px + var(--app-safe-bottom));
  }

  .calc-key {
    width: min(100%, clamp(54px, 16vw, 72px));
    font-size: clamp(18px, 5vw, 22px);
  }

  .calculator-view > .info-card {
    margin-bottom: calc(24px + var(--app-safe-bottom));
  }
}
