@import url('https://fonts.googleapis.com/css2?family=M+PLUS+1+Code:wght@700&display=swap');

:root {
  --bg:      #1e1e2e;
  --surface: #313244;
  --surface2:#585b70;
  --text:    #cdd6f4;
  --subtext: #a6adc8;
  --accent:  #cba6f7;
  --accent2: #89b4fa;
  --border:  #45475a;
  --red:     #f38ba8;
  --green:   #a6e3a1;
}

html[data-theme="mocha"] {
  --bg:      #1e1e2e;
  --surface: #313244;
  --surface2:#585b70;
  --text:    #cdd6f4;
  --subtext: #a6adc8;
  --accent:  #cba6f7;
  --accent2: #89b4fa;
  --border:  #45475a;
  --red:     #f38ba8;
  --green:   #a6e3a1;
}

html[data-theme="latte"] {
  --bg:      #eff1f5;
  --surface: #e6e9f0;
  --surface2:#ccd0da;
  --text:    #4c4f69;
  --subtext: #626d83;
  --accent:  #8839ef;
  --accent2: #1e66f5;
  --border:  #bcc0cc;
  --red:     #d20f39;
  --green:   #40a02b;
}

html[data-theme="frappe"] {
  --bg:      #303446;
  --surface: #414559;
  --surface2:#626880;
  --text:    #c6d0f5;
  --subtext: #949cbb;
  --accent:  #ca9ee6;
  --accent2: #8caaee;
  --border:  #51576d;
  --red:     #e78284;
  --green:   #a6d189;
}

html[data-theme="macchiato"] {
  --bg:      #24273a;
  --surface: #363a4f;
  --surface2:#5b6078;
  --text:    #cad3f5;
  --subtext: #8087a2;
  --accent:  #c6a0f6;
  --accent2: #8aadf4;
  --border:  #494d64;
  --red:     #ed8796;
  --green:   #a6da95;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
}

.canvas {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

body.edit-mode .canvas::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(203,166,247,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(203,166,247,.06) 1px, transparent 1px);
  background-size: 20px 20px;
  pointer-events: none;
  z-index: 0;
}

.top-controls {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 100;
}

.ctrl-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.ctrl-btn:hover { background: var(--border); }
.ctrl-btn:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

body.edit-mode #editModeBtn {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.edit-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-bottom: 1px solid var(--accent);
  font-size: 13px;
  color: var(--subtext);
  z-index: 90;
  transition: height 0.2s ease;
}
.edit-banner.visible {
  height: 42px;
}
.btn-done {
  padding: 4px 14px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.btn-done:hover { opacity: 0.85; }

.add-widget-btn {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 40px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  z-index: 100;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease, background 0.15s;
  pointer-events: none;
}
.add-widget-btn.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: all;
}
.add-widget-btn:hover { background: var(--border); }

.widget-picker {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  width: 280px;
  z-index: 110;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.widget-picker.visible {
  opacity: 1;
  pointer-events: all;
  transform: translateX(-50%) translateY(0);
}
.picker-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--subtext);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
}
.picker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.picker-item:hover {
  background: var(--border);
  border-color: var(--border);
}
.picker-close {
  width: 100%;
  justify-content: center;
}

.widget {
  position: absolute;
  user-select: none;
  border-radius: 8px;
  overflow: visible;
  transition: box-shadow 0.15s;
}

.widget-body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 8px;
}

.widget-edit-bar {
  display: none;
  position: absolute;
  top: -30px;
  right: 0;
  gap: 4px;
  align-items: center;
  z-index: 10;
}
.widget.edit-mode .widget-edit-bar { display: flex; }

.widget-settings-btn,
.widget-remove-btn {
  padding: 3px 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--subtext);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
  transition: background 0.12s, color 0.12s;
}
.widget-settings-btn:hover { background: var(--border); color: var(--text); }
.widget-remove-btn:hover { background: var(--red); color: var(--bg); border-color: var(--red); }

.widget.edit-mode:hover {
  box-shadow: 0 0 0 2px var(--accent);
  cursor: grab;
}
.widget.dragging {
  cursor: grabbing !important;
  box-shadow: 0 8px 32px rgba(0,0,0,.5), 0 0 0 2px var(--accent);
  opacity: 0.9;
}

.resize-handle {
  position: absolute;
  display: none;
  z-index: 10;
}
.widget.edit-mode .resize-handle { display: block; }

.resize-e {
  right: -5px; top: 10%; bottom: 10%;
  width: 10px;
  cursor: ew-resize;
}
.resize-s {
  bottom: -5px; left: 10%; right: 10%;
  height: 10px;
  cursor: ns-resize;
}
.resize-se {
  right: -5px; bottom: -5px;
  width: 16px; height: 16px;
  cursor: nwse-resize;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0.7;
}
.resize-se:hover { opacity: 1; }

.w-clock {
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  gap: 4px;
}
.w-clock-time {
  font-family: 'M PLUS 1 Code', monospace;
  font-weight: 700;
  font-size: clamp(28px, 5vw, 56px);
  color: var(--text);
  line-height: 1;
}
.w-clock-tz {
  font-size: 12px;
  color: var(--subtext);
}

.w-search {
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
}
.w-search-form {
  width: 100%;
  display: flex;
  gap: 8px;
}
.search-input {
  flex: 1;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--subtext); }

.w-weather {
  width: 100%; height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
}
.w-weather-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
}
.w-weather-info { display: flex; flex-direction: column; gap: 2px; }
.w-weather-temp { font-size: 32px; font-weight: 700; color: var(--text); line-height: 1; }
.w-weather-desc { font-size: 13px; color: var(--accent2); }
.w-weather-city { font-size: 12px; color: var(--subtext); }
.w-weather-wind { font-size: 11px; color: var(--subtext); }
.w-weather-loading,
.w-weather-error { font-size: 13px; color: var(--subtext); }
.w-weather-error { color: var(--red); }

.settings-sidebar {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 300px;
  background: var(--surface2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 120;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.settings-sidebar.open { transform: translateX(0); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 119;
}
.sidebar-backdrop.open { display: block; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-title { font-size: 15px; font-weight: 600; color: var(--text); }
.sidebar-close {
  background: none;
  border: none;
  color: var(--subtext);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
}
.sidebar-close:hover { background: var(--border); color: var(--text); }

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.form-row-check { flex-direction: row; align-items: center; }
.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--subtext);
}
.check-label input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }

label {
  font-size: 13px;
  color: var(--subtext);
  font-weight: 500;
}
input[type="text"],
select {
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
input[type="text"]:focus,
select:focus { border-color: var(--accent); }
small { font-size: 12px; color: var(--subtext); }

.btn-primary {
  padding: 10px 16px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:focus { outline: none; }
.btn-primary:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.btn-ghost {
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--border); }

.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.45);
  z-index: 200;
}
.modal-overlay.open { display: flex; }
.modal-content {
  width: min(520px, 94%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.modal-content h2 {
  margin: 0 0 20px;
  font-size: 17px;
  color: var(--text);
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.footer {
  position: fixed;
  bottom: 16px;
  left: 16px;
  font-size: 12px;
  color: var(--subtext);
  z-index: 5;
  pointer-events: none;
  transition: color 0.2s ease;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

@media (max-width: 520px) {
  .w-clock-time { font-size: 36px; }
  .settings-sidebar { width: 100%; }
}