/*
 * パネル、操作バー、通知の帯、操作部品の共通の見た目。値は tokens.css のものだけを使う。
 * 動きは、パネルの開閉と通知の帯の出入りだけに付ける (design.md U2)。
 * 押せる部品は44px以上にし、フォーカスの輪郭を必ず出す。
 */

:where(button, input, select, textarea, a, [tabindex]):focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

button {
  font: inherit;
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------------------- */
/* 操作バー                                                                  */
/* ------------------------------------------------------------------------- */

#controls {
  position: fixed;
  left: 50%;
  bottom: max(var(--space-4), env(safe-area-inset-bottom));
  translate: -50% 0;
  z-index: var(--z-controls);
  display: flex;
  gap: var(--space-1);
  max-width: calc(100% - var(--space-4) * 2);
  overflow-x: auto;
  padding: var(--space-1);
  background: var(--ui-surface);
  color: var(--ui-text);
  border: 1px solid var(--ui-line-soft);
  border-radius: var(--radius-m);
  box-shadow: 0 8px 28px oklch(0 0 0 / 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) linear;
}

#controls.is-shown {
  opacity: 1;
  pointer-events: auto;
}

#controls:empty {
  display: none;
}

.control-btn,
.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--ui-text);
  cursor: pointer;
}

.control-btn:hover,
.icon-btn:hover {
  background: var(--ui-surface-2);
}

.control-btn[aria-pressed="true"] {
  background: var(--ui-surface-2);
  color: var(--ui-accent);
  box-shadow: inset 0 0 0 1px var(--ui-accent);
}

/* ------------------------------------------------------------------------- */
/* パネル                                                                    */
/* ------------------------------------------------------------------------- */

.panel-layer {
  position: fixed;
  inset: 0;
  z-index: var(--z-panel);
}

/*
 * 幅720px以上で右の面を開いている間は、時計の画面を面の左に収める。
 * 設定を変えたときに、時計への反映が見えるようにするため。位置は動かさずに切り替える。
 */
@media (min-width: 720px) {
  body.has-side-panel #stage {
    right: 420px;
  }
}

/* 右から出る面のときは、時計への反映が見えるように、後ろを暗くしない */
.panel-scrim {
  position: absolute;
  inset: 0;
  background: transparent;
}

.panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--ui-surface);
  color: var(--ui-text);
  border-left: 1px solid var(--ui-line-soft);
  box-shadow: -10px 0 36px oklch(0 0 0 / 0.24);
  translate: 100% 0;
  transition: translate var(--dur-spatial) var(--ease-out);
}

.panel-layer.is-open .panel {
  translate: 0 0;
}

.panel.is-wide {
  width: 100%;
  border-left: 0;
  box-shadow: none;
}

@media (max-width: 719.98px) {
  .panel {
    width: 100%;
    border-left: 0;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel {
    translate: 0 0;
    opacity: 0;
    transition: opacity var(--dur-ui) linear;
  }

  .panel-layer.is-open .panel {
    opacity: 1;
  }
}

.panel-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-5);
  border-bottom: 1px solid var(--ui-line-soft);
}

.panel-title {
  margin: 0;
  font-size: var(--fs-heading);
  line-height: var(--lh-tight);
  font-weight: 650;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-2) var(--space-5) var(--space-7);
}

.panel.is-wide .panel-body {
  padding-inline: max(var(--space-5), calc((100% - 1040px) / 2));
}

@media (max-width: 719.98px) {
  .panel-header {
    padding-left: var(--space-4);
  }

  .panel-body,
  .panel.is-wide .panel-body {
    padding-inline: var(--space-4);
  }
}

/* ------------------------------------------------------------------------- */
/* 設定のパネル                                                              */
/* ------------------------------------------------------------------------- */

.settings-section {
  padding-block: var(--space-5) var(--space-3);
}

.settings-section + .settings-section {
  border-top: 1px solid var(--ui-line-soft);
}

.settings-section-title {
  margin: 0 0 var(--space-1);
  font-size: var(--fs-title);
  line-height: var(--lh-tight);
  font-weight: 700;
}

.settings-note,
.row-help,
.confirm-text {
  margin: 0;
  color: var(--ui-text-dim);
  font-size: var(--fs-body);
  line-height: 1.6;
}

.settings-note {
  padding-block: var(--space-2);
}

.settings-group {
  display: grid;
  gap: var(--space-2);
  padding-block: var(--space-3);
}

.settings-group > .row {
  padding-block: var(--space-1);
}

.form-error {
  margin: 0;
  color: var(--ui-danger);
}

.form-error:empty {
  display: none;
}

/* ------------------------------------------------------------------------- */
/* 行                                                                        */
/* ------------------------------------------------------------------------- */

.row {
  display: grid;
  gap: var(--space-2);
  padding-block: var(--space-3);
  min-width: 0;
}

.row-label {
  margin: 0;
  font-size: var(--fs-body);
  font-weight: 400;
  line-height: var(--lh-tight);
}

.row--inline {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: var(--space-4);
}

.row--inline > .row-help {
  grid-column: 1 / -1;
}

/* ------------------------------------------------------------------------- */
/* 操作部品                                                                  */
/* ------------------------------------------------------------------------- */

.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  min-width: 0;
  border: 1px solid var(--ui-line);
  border-radius: var(--radius-s);
  background: var(--ui-surface);
}

/* 幅は文字数に合わせて配分する。収まらない幅では、選択肢ごとに次の行へ送る */
.segmented {
  flex-wrap: wrap;
}

.segmented-option {
  flex: 1 1 auto;
  white-space: nowrap;
  min-height: 44px;
  padding: var(--space-1) var(--space-2);
  border: 0;
  border-radius: calc(var(--radius-s) - 2px);
  background: transparent;
  color: var(--ui-text);
  line-height: var(--lh-tight);
  text-align: center;
  cursor: pointer;
}

.segmented-option:hover:not([aria-checked="true"]):not(:disabled) {
  background: var(--ui-surface-2);
}

.segmented-option[aria-checked="true"] {
  background: var(--ui-accent);
  color: var(--ui-on-accent);
  font-weight: 600;
}

.segmented-option:focus-visible {
  outline-offset: -2px;
  outline-color: var(--ui-text);
}

.segmented-option:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

/* 切り替え。つまみは動かさずに位置を切り替える */
.toggle {
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  margin-block: 6px;
  padding: 0;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-surface-2);
  cursor: pointer;
}

/* 押せる範囲を44pxにする */
.toggle::before {
  content: "";
  position: absolute;
  inset: -7px -2px;
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--ui-text-dim);
}

.toggle[aria-checked="true"] {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
}

.toggle[aria-checked="true"]::after {
  left: 23px;
  background: var(--ui-on-accent);
}

.toggle:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.select,
.text-field {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--ui-line);
  border-radius: var(--radius-s);
  background: var(--ui-surface);
  color: var(--ui-text);
  font: inherit;
}

.text-field::placeholder {
  color: var(--ui-text-dim);
  opacity: 1;
}

.slider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.slider-input {
  flex: 1;
  min-width: 0;
  height: 44px;
  margin: 0;
  accent-color: var(--ui-accent);
}

.slider-value {
  min-width: 3.5em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.slider.is-disabled {
  opacity: 0.55;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid var(--ui-line);
  border-radius: var(--radius-s);
  background: var(--ui-surface);
  color: var(--ui-text);
  font-weight: 600;
  line-height: var(--lh-tight);
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  background: var(--ui-surface-2);
}

.btn--primary {
  background: var(--ui-accent);
  border-color: var(--ui-accent);
  color: var(--ui-on-accent);
}

.btn--primary:hover:not(:disabled) {
  background: var(--ui-accent);
  border-color: var(--ui-text);
}

.btn--danger {
  border-color: var(--ui-danger);
  color: var(--ui-danger);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn .icon {
  width: 20px;
  height: 20px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.confirm-box {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--ui-danger);
  border-radius: var(--radius-s);
}

.confirm-text {
  color: var(--ui-text);
}

/* 世界の時計の一覧 */
.world-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  border-block: 1px solid var(--ui-line-soft);
}

.world-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-block: var(--space-1);
}

.world-item + .world-item {
  border-top: 1px solid var(--ui-line-soft);
}

.world-text {
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--space-3);
  min-width: 0;
}

.world-label {
  font-weight: 600;
}

.world-zone {
  color: var(--ui-text-dim);
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------------- */
/* 通知の帯                                                                  */
/* ------------------------------------------------------------------------- */

#toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(max(var(--space-4), env(safe-area-inset-bottom)) + 52px + var(--space-3));
  translate: -50% 0;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: min(560px, calc(100% - var(--space-4) * 2));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 100%;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  min-height: 52px;
  background: var(--ui-surface);
  color: var(--ui-text);
  border: 1px solid var(--ui-line-soft);
  border-radius: var(--radius-m);
  box-shadow: 0 8px 28px oklch(0 0 0 / 0.22);
  pointer-events: auto;
  opacity: 0;
  translate: 0 12px;
  transition:
    opacity var(--dur-ui) linear,
    translate var(--dur-spatial) var(--ease-out);
}

.toast.is-shown {
  opacity: 1;
  translate: 0 0;
}

.toast-message {
  margin: 0;
  padding-block: var(--space-2);
  padding-right: var(--space-2);
  line-height: 1.5;
}

.toast-action {
  flex: none;
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    translate: 0 0;
  }
}
