@font-face {
  font-family: "DM Sans";
  src: url("./assets/fonts/dm-sans-variable.woff2") format("woff2");
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: system-ui, "Malgun Gothic", sans-serif;
  color: #f9f4e9;
  background: #181b16;
  --scene: url("./assets/scenes/rainy-hanok.webp");
  --focal-point: 59% center;
  --accent: #ded8ab;
  --line: rgb(255 247 233 / 26%);
  --glass: rgb(22 23 18 / 63%);
}

:root:lang(ja) { font-family: "Yu Gothic UI", "Hiragino Sans", system-ui, sans-serif; }
:root:lang(zh-CN) { font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif; }
:root:lang(zh-TW) { font-family: "Microsoft JhengHei UI", "PingFang TC", system-ui, sans-serif; }

:root[data-scene="sunlit-room"] {
  --scene: url("./assets/scenes/sunlit-room.webp");
  --focal-point: 72% center;
  --accent: #f5d095;
}

:root[data-scene="candlelit-hall"] {
  --scene: url("./assets/scenes/candlelit-hall.webp?v=3");
  --focal-point: center;
  --accent: #f0bc90;
}

*, *::before, *::after { box-sizing: border-box; }

body { margin: 0; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid #f1db9f; outline-offset: 4px; }

.landscape, .shade, .effects {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.landscape {
  background-image: var(--scene);
  background-size: cover;
  background-position: var(--focal-point);
}

.shade {
  background:
    radial-gradient(ellipse 30rem 22rem at 50% 45%, rgb(10 10 7 / 43%), transparent),
    linear-gradient(180deg, rgb(14 13 10 / 23%), transparent 33%, transparent 61%, rgb(14 13 10 / 45%)),
    rgb(15 14 11 / 10%);
}

.stage {
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  place-items: center;
  padding: clamp(1rem, 4svh, 3rem) .9rem 1.25rem;
}

.timer { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; width: min(100%, 38rem); }

.phase {
  min-height: 1.15rem;
  margin: 0;
  color: #fff6e7;
  font-size: .83rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-shadow: 0 1px 12px #151410;
}

.time {
  margin: .15rem 0 .55rem;
  color: #fff6e7;
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: clamp(4.9rem, 18vw, 12.75rem);
  font-weight: 340;
  font-variant-numeric: lining-nums tabular-nums;
  line-height: 1.04;
  white-space: nowrap;
  text-shadow: 0 .17rem 2.2rem rgb(0 0 0 / 50%);
}

.time-digits { display: inline-flex; gap: .045em; }
.time-digits span { width: .6em; text-align: center; }
.time-separator { margin-inline: .1em; }
.time.is-wide { font-size: clamp(4rem, 15vw, 10.9rem); }
.progress { width: 6rem; height: 2px; overflow: hidden; background: var(--line); border-radius: 1rem; }
.progress span { display: block; width: 100%; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; }

.timer-actions { display: flex; align-items: center; gap: .7rem; margin-top: 1.35rem; }

.start-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .65rem;
  min-width: 8.5rem;
  min-height: 3.16rem;
  padding: .5rem 1rem;
  border: 1px solid #f6ebd4;
  border-radius: 99rem;
  background: #f6ebd4;
  color: #26251c;
  font-size: .9rem;
  font-weight: 700;
}

.start-button:hover { background: #fff8e9; }

.playback-button { width: 3.35rem; height: 3.35rem; min-width: 0; padding: 0; }

.play-icon {
  width: .76rem;
  height: .9rem;
  margin-inline-start: .12rem;
  border-top: .45rem solid transparent;
  border-bottom: .45rem solid transparent;
  border-left: .76rem solid currentColor;
}

.is-running .play-icon { margin: 0; border: solid; border-width: 0 2px; }

.reset-button, .utility-button, .effect-controls {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  border-radius: 99rem;
}

.reset-button {
  display: grid;
  place-items: center;
  width: 3.16rem;
  height: 3.16rem;
  padding: 0 0 .12rem;
  font: 1.6rem / 1 system-ui, sans-serif;
}

.reset-button:hover, .utility-button:hover { background: rgb(55 51 38 / 86%); }

.scene-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(.45rem, 1.6vw, .75rem);
  width: min(100%, 24rem);
  margin-top: clamp(1.45rem, 4.5vh, 2.5rem);
}

.scene-card {
  position: relative;
  min-width: 0;
  padding: .19rem;
  background: rgb(22 22 17 / 74%);
  border: 1px solid var(--line);
  border-radius: .76rem;
  box-shadow: 0 .3rem 1.2rem rgb(0 0 0 / 27%);
}

.scene-card:hover { border-color: #fff2cf; }
.scene-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 .3rem 1.2rem rgb(0 0 0 / 29%); }
.scene-card img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; border-radius: .52rem; }

.scene-card[aria-pressed="true"]::after {
  position: absolute;
  inset: auto .44rem .44rem auto;
  width: .48rem;
  height: .48rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgb(20 19 15 / 72%);
  content: "";
}

.appearance-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  margin-top: .95rem;
}

.effect-controls { display: flex; align-items: center; gap: .12rem; padding: .16rem; }

.effect-controls button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 99rem;
  background: transparent;
}

.effect-controls button:hover { background: rgb(255 247 233 / 12%); }
.effect-controls button[aria-pressed="true"] { color: var(--accent); background: rgb(249 243 226 / 18%); border-color: rgb(249 243 226 / 24%); }

.effect-icon { position: relative; display: block; flex: none; width: .9rem; height: .9rem; }
.snow-icon { font: 1rem / .9rem system-ui, sans-serif; }
.rain-icon::before { content: ""; position: absolute; inset: .1rem .17rem .13rem; border: 1px solid; border-radius: 80% 0 70% 55%; transform: rotate(-45deg); }
.bubble-icon::before, .bubble-icon::after { content: ""; position: absolute; border: 1px solid; border-radius: 50%; }
.bubble-icon::before { inset: .16rem .22rem .06rem .02rem; }
.bubble-icon::after { inset: .01rem -.05rem .51rem .57rem; }
.firefly-icon::before, .firefly-icon::after { content: ""; position: absolute; border-radius: 50%; background: currentColor; }
.firefly-icon::before { top: .36rem; left: .19rem; width: .32rem; height: .32rem; }
.firefly-icon::after { top: .12rem; right: .03rem; width: .2rem; height: .2rem; box-shadow: -.19rem .56rem 0 currentColor; }
.effect-controls button[data-effect="fireflies"][aria-pressed="true"] { color: #cefb9d; }

.utility-controls { display: flex; gap: .4rem; }
.utility-button { display: grid; place-items: center; width: 2.85rem; height: 2.85rem; padding: 0; }
.clock-icon { position: relative; width: 1.08rem; height: 1.08rem; border: 1.4px solid currentColor; border-radius: 50%; }
.clock-icon::after { position: absolute; top: .21rem; left: .44rem; width: .28rem; height: .31rem; border: solid; border-width: 0 0 1.4px 1.4px; border-radius: 0 0 0 1px; content: ""; }
.globe-icon { position: relative; width: 1.1rem; height: 1.1rem; border: 1.4px solid currentColor; border-radius: 50%; }
.globe-icon::before { position: absolute; inset: -1px 3px; border: 1px solid currentColor; border-radius: 50%; content: ""; }
.globe-icon::after { position: absolute; inset: 50% 0 auto; border-top: 1px solid currentColor; content: ""; }

.effects { overflow: hidden; }
.effect-particle {
  position: absolute;
  left: var(--x);
  width: var(--size);
  height: var(--size);
  opacity: var(--opacity);
  animation-duration: var(--duration);
  animation-delay: var(--delay);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  will-change: transform;
}

.effects[data-effect="snow"] .effect-particle {
  top: -2vh;
  border-radius: 50%;
  background: #fff6e3;
  box-shadow: 0 0 .32rem rgb(255 240 211 / 54%);
  animation-name: snow-fall;
}

.effects[data-effect="snow"] .snow-crystal {
  background: none;
  box-shadow: none;
  animation-name: snow-fall, snow-fade;
}
.snow-crystal::before {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff4dd;
  font: calc((var(--size) + 5px) * var(--crystal-scale)) / 1 "Segoe UI Symbol", sans-serif;
  text-shadow: 0 0 .26rem rgb(255 238 202 / 55%);
  content: "\2744\FE0E";
}

.effects[data-effect="rain"] .effect-particle {
  top: -7vh;
  width: 1.2px;
  background: linear-gradient(transparent, rgb(220 229 220 / 25%) 46%, rgb(237 235 213 / 66%) 82%, transparent);
  border-radius: 2px;
  animation-name: rain-fall;
}

.effects[data-effect="bubbles"] .effect-particle {
  bottom: -7vh;
  border: 1px solid rgb(253 232 216 / 32%);
  border-radius: 50%;
  background:
    radial-gradient(circle at 28% 23%, rgb(255 250 232 / 70%), transparent 29%),
    radial-gradient(circle at 70% 72%, rgb(230 170 188 / 31%), transparent 56%);
  box-shadow: inset .08em .1em .36em rgb(255 233 182 / 30%), inset -.18em -.1em .45em rgb(169 203 219 / 32%), 0 0 .28em rgb(248 218 197 / 18%);
  animation-name: bubble-rise;
}

.effects[data-effect="fireflies"] .effect-particle {
  top: var(--y);
  border-radius: 50%;
  background: #e7ffbb;
  box-shadow: 0 0 .32rem .07rem rgb(158 235 91 / 88%), 0 0 .8rem .17rem rgb(126 210 62 / 44%);
  animation-name: firefly-drift, firefly-glow;
  animation-duration: var(--duration), calc(var(--duration) * .46);
  animation-delay: var(--delay), var(--delay);
  animation-timing-function: ease-in-out;
  animation-direction: alternate;
}

@keyframes snow-fall {
  40% { transform: translate3d(1rem, 43vh, 0); }
  75% { transform: translate3d(-.65rem, 80vh, 0); }
  100% { transform: translate3d(var(--drift), 107vh, 0); }
}

@keyframes snow-fade {
  0%, 100% { opacity: 0; }
  8%, 92% { opacity: var(--opacity); }
}

@keyframes rain-fall {
  from { transform: rotate(12deg); }
  to { transform: translate3d(-17vw, 112vh, 0) rotate(12deg); }
}

@keyframes bubble-rise {
  0% { opacity: 0; }
  16%, 83% { opacity: var(--opacity); }
  42% { transform: translate3d(calc(var(--drift) * .7), -48vh, 0); }
  73% { transform: translate3d(calc(var(--drift) * .3), -84vh, 0); }
  100% { opacity: 0; transform: translate3d(var(--drift), -115vh, 0); }
}

@keyframes firefly-drift {
  40% { transform: translate3d(var(--drift), var(--rise), 0); }
  72% { transform: translate3d(calc(var(--drift) * .3), calc(var(--rise) * 1.35), 0); }
  100% { transform: translate3d(calc(var(--drift) * 1.5), calc(var(--rise) * -.35), 0); }
}

@keyframes firefly-glow {
  0%, 9% { opacity: .06; }
  65% { opacity: var(--opacity); }
  100% { opacity: .27; }
}

@media (prefers-reduced-motion: reduce) {
  .effects { display: none; }
}

.panel {
  width: min(23rem, calc(100vw - 1.5rem));
  max-height: calc(100svh - 2rem);
  overflow: auto;
  padding: clamp(1rem, 3.5vw, 1.55rem);
  border: 1px solid var(--line);
  border-radius: 1.35rem;
  background: #22231c;
  color: inherit;
  box-shadow: 0 1rem 4rem rgb(0 0 0 / 45%);
}

.panel::backdrop { background: rgb(12 12 9 / 56%); backdrop-filter: blur(3px); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.panel-heading h2 { margin: 0; font-size: 1.12rem; font-weight: 650; }

.close-button {
  display: grid;
  place-items: center;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  font-size: 1.5rem;
}

.close-button:hover { background: rgb(255 247 233 / 10%); }
.duration-fields { display: grid; gap: .82rem; }
.duration-fields label, .notification-field { display: flex; align-items: center; justify-content: space-between; gap: .6rem; font-size: .93rem; }
.field-value { white-space: nowrap; }
.duration-fields input { width: 4.25rem; padding: .43rem .3rem .43rem .55rem; color: inherit; border: 1px solid var(--line); border-radius: .4rem; background: #303126; }
.rounds-help, .notification-status { margin: .58rem 0 0; color: #d5cbbc; font-size: .76rem; line-height: 1.5; }
.notification-status:empty { margin: 0; }
.notification-field { margin-top: 1rem; padding-top: .85rem; border-top: 1px solid var(--line); }
.notification-field button { min-height: 2.75rem; padding: .25rem .7rem; color: inherit; border: 1px solid var(--line); border-radius: 99rem; background: #303126; font-size: .78rem; }
.notification-field button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.save-button { width: 100%; margin-top: 1.15rem; }

.language-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.language-options button { min-height: 2.75rem; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: .6rem; background: #303126; text-align: start; font-size: .87rem; }
.language-options button:hover { background: #424236; }
.language-options button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

.toast {
  position: fixed;
  inset: auto 0 max(1rem, env(safe-area-inset-bottom));
  z-index: 1;
  width: max-content;
  max-width: calc(100% - 2rem);
  margin: 0 auto;
  padding: .65rem .9rem;
  color: #fff6e7;
  background: #24251d;
  border: 1px solid var(--line);
  border-radius: .65rem;
  font-size: .85rem;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

.toast:empty { padding: 0; border: 0; }

@media (max-width: 360px) {
  .appearance-controls, .utility-controls { gap: .23rem; }
  .effect-controls { gap: 0; padding: .08rem; }
  .utility-button { width: 2.75rem; height: 2.75rem; }
}

@media (max-height: 540px) {
  .stage { padding-block: .65rem; }
  .time { font-size: clamp(4.4rem, min(20vh, 19.5vw), 8.25rem); }
  .time.is-wide { font-size: clamp(3.85rem, min(18vh, 16vw), 7.25rem); }
  .timer-actions { margin-top: .65rem; }
  .scene-grid { width: min(100%, 19rem); margin-top: .85rem; }
  .appearance-controls { margin-top: .65rem; }
}
