html {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

h1 {
  margin: 4px;
  padding: 4px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  backdrop-filter: blur(10px);
  background-color: rgba(0, 0, 0, 0.25);
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 9999;
  height: 44px;
  align-items: center;
}

.window {
  border: 1px solid #d1d1d1;
  border-radius: 8px;
  padding: 0;
  margin: 16px;
  background-color: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  position: absolute;
  top: 100px;
  left: 100px;
  width: 300px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.windowheader {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: move;
  margin: 0;
  padding: 0 12px;
  background: linear-gradient(180deg, #f6f6f6 0%, #e8e8e8 100%);
  border-bottom: 1px solid #d1d1d1;
  font-size: 13px;
  font-weight: 500;
  color: #333;
  position: relative;
  touch-action: none;
}

.closebutton {
  position: absolute;
  left: 8px;
  top: 8px;
  width: 20px;
  height: 20px;
  background-color: #ff5f56;
  border: 1px solid #e0443e;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  color: #8b0000;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.closebutton:hover {
  background-color: #ff7a71;
  transform: scale(1.1);
}

.closebutton:active {
  background-color: #ff3b30;
  transform: scale(0.95);
}

/* Window content area */
.window-content {
  padding: 16px;
}

/* Alternative header styles for different window types */
.windowheader.dark {
  background: linear-gradient(180deg, #4a4a4a 0%, #2c2c2c 100%);
  color: #fff;
  border-bottom: 1px solid #1a1a1a;
}

.windowheader.accent {
  background: linear-gradient(180deg, #007aff 0%, #0056d1 100%);
  color: #fff;
  border-bottom: 1px solid #0040a0;
}

/* Window states */
.window.focused {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  z-index: 1000;
}

.window.minimized {
  transform: scale(0.1);
  opacity: 0;
  pointer-events: none;
}

.selected {
    background-color: rgba(240, 240, 240, 0.8) !important;
    border: 2px solid #fff !important;
    border-radius: 8px !important;
}

/* Desktop Apps Container */
#desktopApps {
  padding-top: 64px;
  padding-left: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

#desktopApps > div {
  text-align: center;
  padding: 16px;
  filter: drop-shadow(0 0 8px black);
  width: fit-content;
  cursor: pointer;
  min-width: 80px;
  transition: transform 0.2s ease;
}

#desktopApps > div:active {
  transform: scale(0.95);
}

#desktopApps img {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: block;
  margin: 0 auto 8px;
}

#desktopApps p {
  margin: 0;
  color: #fff;
  font-size: 14px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

/* Notes App Styles */
#notes {
  width: 600px;
  height: 400px;
  resize: both;
  overflow: hidden;
}

/* Canvas App Styles */
#canvas {
  width: 650px;
  height: 500px;
  resize: both;
  overflow: hidden;
}

.canvas-container {
  display: flex;
  flex-direction: column;
  height: 456px; /* Adjusted for header height */
  background-color: #fff;
}

.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background-color: #f8f8f8;
  border-bottom: 1px solid #d1d1d1;
  flex-shrink: 0;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  background: #fff;
  border: 1px solid #d1d1d1;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
  min-width: 36px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-btn:hover {
  background-color: #f0f0f0;
  border-color: #007aff;
}

.tool-btn.active {
  background-color: #007aff;
  color: white;
  border-color: #007aff;
}

#colorPicker {
  width: 32px;
  height: 32px;
  border: 1px solid #d1d1d1;
  border-radius: 6px;
  cursor: pointer;
  background: none;
  padding: 0;
}

#brushSize {
  width: 80px;
}

#brushSizeDisplay {
  font-size: 12px;
  color: #666;
  min-width: 30px;
}

.canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
  overflow: auto;
}

#drawingCanvas {
  border: 1px solid #d1d1d1;
  background: white;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.notes-container {
  display: flex;
  height: 356px; /* Adjusted for header height */
  background-color: #fff;
}

.notes-sidebar {
  width: 200px;
  background-color: #f5f5f5;
  border-right: 1px solid #d1d1d1;
  overflow-y: auto;
}

.note-item {
  padding: 12px;
  border-bottom: 1px solid #e1e1e1;
  cursor: pointer;
  transition: background-color 0.2s ease;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.note-item:hover {
  background-color: #e8e8e8;
}

.note-item.active {
  background-color: #007aff;
  color: white;
}

.note-item.active:hover {
  background-color: #0056d1;
}

.note-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-date {
  font-size: 11px;
  color: #666;
  margin-bottom: 4px;
}

.note-item.active .note-date {
  color: #ccc;
}

.note-preview {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item.active .note-preview {
  color: #ddd;
}

.notes-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background-color: #fff;
}

.note-content {
  display: none;
}

.note-content.active {
  display: block;
}

.note-content[contenteditable="true"]:focus {
  outline: none;
  background-color: #fafafa;
}

.note-content[contenteditable="true"]:hover {
  background-color: #fdfdfd;
}

.note-content h2 {
  margin-top: 0;
  color: #333;
  font-size: 18px;
  font-weight: 600;
}

.note-content p {
  line-height: 1.6;
  color: #444;
  margin-bottom: 12px;
}

.note-content ul {
  padding-left: 20px;
}

.note-content li {
  margin-bottom: 6px;
  color: #444;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  body {
    background-size: cover !important;
    background-attachment: fixed !important;
  }

  .topbar {
    height: 50px;
    padding: 0 16px;
    box-sizing: border-box;
  }

  .topbar p {
    font-size: 16px;
    margin: 0 !important;
    line-height: 50px;
    display: flex;
    align-items: center;
    height: 50px;
  }

  #desktopApps {
    padding-top: 70px;
    padding-left: 20px;
    padding-right: 20px;
    justify-content: center;
  }

  #desktopApps > div {
    padding: 20px;
    min-width: 100px;
  }

  #desktopApps img {
    width: 80px;
    height: 80px;
  }

  #desktopApps p {
    font-size: 16px;
  }

  /* Mobile Window Styles */
  .window {
    position: fixed !important;
    top: 50px !important;
    left: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 50px) !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    max-width: none !important;
    max-height: none !important;
  }

  .windowheader {
    height: 50px;
    font-size: 16px;
    cursor: default;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
  }

  .closebutton {
    width: 24px;
    height: 24px;
    left: 16px;
    top: 13px;
  }

  /* Mobile Notes App */
  #notes {
    width: 100vw !important;
    height: calc(100vh - 50px) !important;
    resize: none !important;
  }

  /* Mobile Canvas App */
  #canvas {
    width: 100vw !important;
    height: calc(100vh - 50px) !important;
    resize: none !important;
  }

  .canvas-container {
    height: calc(100vh - 100px) !important;
  }

  .canvas-toolbar {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
  }

  .tool-group {
    justify-content: center;
    width: 100%;
    flex-wrap: wrap;
  }

  .tool-btn {
    font-size: 16px;
    min-width: 44px;
    height: 44px;
    touch-action: manipulation;
  }

  #colorPicker {
    width: 44px;
    height: 44px;
  }

  #brushSize {
    width: 140px;
  }

  .canvas-wrapper {
    padding: 8px;
  }

  #drawingCanvas {
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 250px);
    width: auto;
    height: auto;
  }

  .notes-container {
    height: calc(100vh - 100px) !important;
    flex-direction: column;
  }

  .notes-sidebar {
    width: 100% !important;
    height: 200px;
    border-right: none;
    border-bottom: 1px solid #d1d1d1;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    flex-direction: row;
  }

  .note-item {
    min-width: 150px;
    max-width: 150px;
    flex-shrink: 0;
    padding: 16px;
    min-height: 60px;
    border-bottom: none;
    border-right: 1px solid #e1e1e1;
  }

  .notes-content {
    flex: 1;
    height: calc(100% - 200px);
    padding: 20px;
  }

  .note-content h2 {
    font-size: 20px;
  }

  .note-content p {
    font-size: 16px;
    line-height: 1.8;
  }

  /* Hide window dragging on mobile */
  .windowheader {
    touch-action: auto;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 0 12px;
  }

  .topbar p {
    font-size: 14px;
    line-height: 50px;
  }

  .closebutton {
    left: 12px;
    top: 13px;
  }

  #desktopApps {
    padding-left: 16px;
    padding-right: 16px;
  }

  #desktopApps > div {
    padding: 16px;
    min-width: 80px;
  }

  #desktopApps img {
    width: 64px;
    height: 64px;
  }

  #desktopApps p {
    font-size: 14px;
  }

  .notes-sidebar {
    height: 150px;
  }

  .note-item {
    min-width: 120px;
    max-width: 120px;
    padding: 12px;
    min-height: 50px;
  }

  .note-title {
    font-size: 13px;
  }

  .note-date {
    font-size: 10px;
  }

  .note-preview {
    font-size: 11px;
  }

  .notes-content {
    padding: 16px;
    height: calc(100% - 150px);
  }

  .note-content h2 {
    font-size: 18px;
  }

  .note-content p {
    font-size: 15px;
  }
}

/* Landscape tablet optimization */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
  .notes-container {
    flex-direction: row;
  }

  .notes-sidebar {
    width: 250px !important;
    height: auto;
    border-right: 1px solid #d1d1d1;
    border-bottom: none;
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .note-item {
    min-width: auto;
    max-width: none;
    flex-shrink: 1;
    border-right: none;
    border-bottom: 1px solid #e1e1e1;
    display: flex;
    flex-direction: column;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .closebutton {
    width: 28px;
    height: 28px;
  }

  .note-item {
    padding: 16px;
    min-height: 50px;
  }

  .windowheader {
    height: 50px;
  }
}
